Results: 1022
Only the post author will be able to edit the post
public function edit($id)
{
    $post = POST::find($id);

    // Check for correct user
    if (auth()->user()->id !== $post->user_id) {
        return redirect('/posts')->with('error', 'Unauthorized page');
    }

    return view('posts.edit')->with('post', $post);
}
It will remove devDependencies from
package.json
like
bootstrap, jquery, popper.js, vue
(removes frontend scaffolding)
php artisan preset none
Except the following packages
"devDependencies": {
    "axios": "^0.19",
    "cross-env": "^7.0",
    "laravel-mix": "^5.0.1",
    "lodash": "^4.17.19",
    "resolve-url-loader": "^3.1.0",
    "sass": "^1.15.2",
    "sass-loader": "^8.0.0"
}
Lists all the available commands
php artisan
Deletes the specified post
public function destroy($id)
{
    $post = POST::find($id);
    $post->delete();    
    return redirect('/posts')->with('success', 'Post Removed');
}
If we want to parse HTML saved by
ckeditor
we should use
{!!$post->body!!}
instead of
{{$post->body}}
Redirects to
/posts
(with success message) after successfully saving the post
public function store(Request $request)
{
    // Validating

    // Saving
    
    // Redirecting
    return redirect('/posts')->with('success', 'Post created');
}
validate
method validates
title
and
name
fields
$request->validate([
    'title' => 'required|unique:posts|max:255',
    'name' => 'required',
]);
Common file for
errors
or session (
success
&
error
) statuses. Then we can include the file inside blade template
@include('inc.messages')
Located at
resources/views/inc/messages.blade.php
In controller we have to use
paginate
method
public function index()
{
    $posts = Post::orderBy('title', 'asc')->paginate(1);
    return $posts;
}
In blade template we will have pagination
{{$posts->links()}}
if there are less records then per page, pagination will not appear
public function index()
{
    $posts = DB::select('SELECT * FROM posts');
    return view('posts.index')->with('posts', $posts);
}
If we want to use the above query, we have to bring in the
DB
class
use DB;
Results: 1022