Today I Learned

Laravel

<TIL

Eloquent return only/latest n rows

Redirect to Controller method with parameters

return redirect()->action('SomeController@method', ['param' => $value]);

dd() at the end of a Eloquent sentence

$users = User::where('name', 'Mary')->get()->dd();

source

auth() in Blade

To check whether an use is authenticated or not, use the @auth directive:

@auth
 <h1> You are now authenticated! </h1>
@endauth

hasMany with specific checks

Filter out records that have n amount of children records:

$authors = Author::has('books', '>', 5)->get();

Where date methods in Eloquent

$items = Item::whereMonth('created_at', '12')->get();
$items = Item::whereDay('created_at', '31')->get();
$items = Item::whereYear('created_at', '2017')->get();
$items = Item::whereDate('created_at', '2017-01-31')->get();
$items = Item::whereTime('created_at', '12:34:56')->get();

source

Run specific migration directory

php artisan make:migration --path="app/some_folder/some_migrations_folder" name_of_migration php artisan migrate --path="app/some_folder/some_migrations_folder"