title
descending$posts = Post::orderBy('title', 'asc')->get();
return view('posts.index')->with('posts', $posts);
where
methodpublic function index()
{
$posts = Post::where('title', 'pst')->get();
return view('posts.index')->with('posts', $posts);
}
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
classuse DB;
paginate
methodpublic 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
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
validate
method validates title
and name
fields$request->validate([
'title' => 'required|unique:posts|max:255',
'name' => 'required',
]);
/posts
(with success message) after successfully saving the postpublic function store(Request $request)
{
// Validating
// Saving
// Redirecting
return redirect('/posts')->with('success', 'Post created');
}
ckeditor
we should use {!!$post->body!!}
instead of {{$post->body}}
public function destroy($id)
{
$post = POST::find($id);
$post->delete();
return redirect('/posts')->with('success', 'Post Removed');
}
php artisan