- use Where function after defining route to set the condition (->where([ 'id' => '[0-9]+', ]))
- or just go to RouteServiceProvider file and define in boot function
- Route::pattern('id', '[0-9]+')
- abort_if(!isset($posts[$id]), 404) // with a status code
- User::factory()->count(5)->create()
- User::where('id', '>=', 2)->orderBy('id', 'desc')->get()
- php artisan make:request StorePost
- define validation in rules method
- composer require laravel/ui
- php artisan ui bootstrap
- php artisan ui:controllers
- npm i && npm run dev
- npm run prod
- in webpack file do mix.version()
- vendor\bin\phpunit
- after setting up the testing dB env in phpunit.xml and config/database.php
- php artisan config:clear
- php artisan make:test HomeTest
- php artisan make:test PostTest
- $posts = BlogPost::with('comments')->get() // will retrieve all comments
- $posts = BlogPost::all()
- $post = BlogPost::findOrFail(3)
- $post->comments
- use Illuminate\Support\Facades\DB
- DB::connection()->enableQueryLog()
- some functions or lines of code
- DB::getQueryLog()
- $post = new BlogPost()
- $post->title = "Nice Title"
- $post->content = "Nice Content"
- $post->save()
- $comment = new Comment()
- $comment->content = "Nice Comment"
- $comment->blog_post_id = $post->id
- $comment->save()
- BlogPost::has('comments')->get()
- BlogPost::has('comments', '>=', 2)->get() // it will retrieve the post which have comments more or equal than 2
- BlogPost::whereHas('comments', function ($query) { $query->where('content', 'like', '%ice%'); })->get()
- BlogPost::doesntHave('comments')->get()
- BlogPost::whereDoesntHave('comments', function ($query) { $query->where('content', 'like', '%abc%'); })->get()
- BlogPost::withCount('comments')->get()
- BlogPost::withCount(['comments', 'comments as new_comments' => function ($query) { $query->where('created_at', '>=', '2020-12-01 08:41:38'); }])->get()