Results: 1580
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
Lists all records of the model ordered by
title
descending
$posts = Post::orderBy('title', 'asc')->get();
return view('posts.index')->with('posts', $posts);
by Valeri Tandilashvili
4 years ago
0
Laravel
model methods
Laravel From Scratch
0
Filters result using the
where
method
public function index()
{
    $posts = Post::where('title', 'pst')->get();
    return view('posts.index')->with('posts', $posts);
}
by Valeri Tandilashvili
4 years ago
0
Laravel
model methods
Laravel From Scratch
0
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;
by Valeri Tandilashvili
4 years ago
0
Laravel
DB methods
Laravel From Scratch
0
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
by Valeri Tandilashvili
4 years ago
0
Laravel
model methods
Laravel From Scratch
0
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
by Valeri Tandilashvili
4 years ago
0
Laravel
Laravel From Scratch
0
validate
method validates
title
and
name
fields
$request->validate([
    'title' => 'required|unique:posts|max:255',
    'name' => 'required',
]);
by Valeri Tandilashvili
4 years ago
0
Laravel
validation
Laravel From Scratch
0
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');
}
by Valeri Tandilashvili
4 years ago
0
Laravel
Laravel From Scratch
0
If we want to parse HTML saved by
ckeditor
we should use
{!!$post->body!!}
instead of
{{$post->body}}
by Valeri Tandilashvili
4 years ago
0
Laravel
packages
Laravel From Scratch
0
Deletes the specified post
public function destroy($id)
{
    $post = POST::find($id);
    $post->delete();    
    return redirect('/posts')->with('success', 'Post Removed');
}
by Valeri Tandilashvili
4 years ago
0
Laravel
model methods
Laravel From Scratch
0
Lists all the available commands
php artisan
by Valeri Tandilashvili
4 years ago
0
Laravel
artisan commands
0
Results: 1580