what are the routes you can read elsewhere, here I'm focusing on using them in Laravel 6.
In order to point our content in the right direction, we have to use them in a Laravel way. Here is a Resouce controller list of all the options:
1. We need a route.
2. We have to have a controller.
3. We have to have a model if we want to talk to our DB.
4. We have to have some content to direct our routes.
Let's start from Route first:
Based on the table, if we want to create a new post let say, we should use a route in our web.php file like this:
Route::get('/posts', 'PostsController@create');
So, get will get the content from our form let say in a New Post page called create.blade.php which we will have in the 'posts' folder which is located in our 'views' folder, which is in 'resources' folder.
/posts is the location to go to.
PostsController@create is our Posts controller and after @ 'create' is our Action which will trigger the post to be saved later in our DB by using GET - in our table in Verb section.
Now we can make a View page in a 'post' directory containing create - to create a new post. Next edit to edit existing posts. Next index to show all the posts and last show, to show a particular post only.
I like to follow names with blade.php, here is an example:
This way, I always know what is where. As well I can use a blade engine in each project. And let say if I want to create a profile, not even a post link with a user id in the menu, I know that I can use like in an example here:
"/profile/{{ Auth::user()->profile->id }}"
The following folder structure saves me time because I don't have to memorize each time where it is.
When you'll follow this table, your routes in web.php should look like that if you have used the post as your model:
But, there's one more thing. You can do it quicker by using Route::resource. I'll describe it next time.



No comments:
Post a Comment