The solution is in Part B.
Let’s first see how merge() helper function works in Laravel:
The merge
method merges the given array or collection with the original array or collection. If a string key in the given items matches a string key in the original collection, the given items's value will overwrite the value in the original collection:
$collection = collect(['product_id' => 1, 'price' => 100]);
adding or updating the collection:
$merged = $collection->merge(['price' => 200, 'discount' => false]);
The new collection will be:
$merged->all();
// ['product_id' => 1, 'price' => 200, 'discount' => false]
If the given array is not an associative array (the given items’s keys are numeric), the values will be appended to the end of the collection. …
In general, you can check simply using:
use Illuminate\Support\Collection;
....
if($variable instanceof Collection) {
....
}
In fact, we are checking whether the $variable
is a Collection-object or not.
Another example:
We know that Illuminate\Database\Eloquent\Collection
extends from Illuminate\Support\Collection
$record = User::all();
dump($record instanceof \App\User); // returns false
dump($record instanceof \Illuminate\Database\Eloquent\Collection); // returns true
This is what we usually do in a controller to validate a request:
$validated = $request->validate([
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);
Since the validate() method is not accessible in a Laravel middleware we should use facade for validating a request inside the middleware.
use Illuminate\Support\Facades\Validator;
and then :
$validator = Validator::make($request->all(), [
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);
To see all your routes compactly, you need to do:
php artisan route:list --compact
php artisan optimize will do the following tasks:
You have one .env
file, but the contents can differ on each machine you run the application.
Do not forget to run the command php artisan config:clear
after you have made the changes to the .env file. Do this php artisan env
, which will return the correct version and assures you about what it is actually set!
The role of the .env
file is to allow you to have different settings depending on which machine you are running your application. So on your production server, the .env
file settings would be different from your local development environment.
production and local are just environment names that you can use to turn certain testing features on or off in different places. …
php artisan vendor:publish
Then just select the number you want:
For opening your current working directory in PhpStorm
You need first open Phpstrom and then go to Tools menu and find the
Create Command-line launcher
Tools -> Create command line launcher
Then it will open a window which is for “Create Launcher Script”
I introduce two useful tools, website and software, for sketching and testing online an Automaton DFA, NFA, eNFA or a regex.
1-
http://ivanzuzak.info/noam/webapps/fsm_simulator/
2-
http://www.jflap.org/
3- comparison
If you know more please complete me.
A curated list of amazingly awesome PHP libraries, resources and shiny things.
A curated list of awesome Python frameworks, libraries, software and resources.
About