Results: 1578
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
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
5 years ago
0
Laravel
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
5 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
5 years ago
0
Laravel
DB 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
5 years ago
0
Laravel
model methods
Laravel From Scratch
0
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
5 years ago
0
Laravel
model methods
Laravel From Scratch
0
Lists all records of the model
$posts = Post::All();
return view('posts.index')->with('posts', $posts);
by Valeri Tandilashvili
5 years ago
0
Laravel
model methods
Laravel From Scratch
0
Sets timestamps to false (default is
true
)
class Post extends Model
{
    // Timestamps
    public $timestamps = false;
}
by Valeri Tandilashvili
5 years ago
0
Laravel
models
Laravel From Scratch
0
Sets primary key for the model (default is
id
)
class Post extends Model
{
    // Primary key
    public $primaryKey = 'record_id';
}
by Valeri Tandilashvili
5 years ago
0
Laravel
models
Laravel From Scratch
0
Sets table name for the model (default is lowercase plural form, in this case
posts
)
class Post extends Model
{
    // Table Name
    protected $table = 't_posts';
}
by Valeri Tandilashvili
5 years ago
0
Laravel
models
Laravel From Scratch
0
Creates all 7 routes for the resource to cover CRUD functionality
Route::resource('posts', 'PostsController');
These routes are:
GET
at
posts
to list all the posts
POST
at
posts
to store new post
GET
at
posts/create
to show form for creating new post
GET
at
posts/{post}
to show the post
PUT
at
posts/{post}
to update the post
DELETE
at
posts/{post}
to delete the post
GET
at
posts/{post}/edit
to show edit form
by Valeri Tandilashvili
5 years ago
0
Laravel
routes
Laravel From Scratch
1
Results: 1578