All request of our new Laravel application will be handled by Laravel’s Illuminate\Http\Request class also we can retrieve the cookie, file, input that were submitted with the request.

When user submit in form we can get the information using Request class .

Form:

<form action="posts/1/comments" method="post">
    @csrf
    <input type="text" name="name" placeholder="name">
    <input type="submit" value="submit">
</form>

 

Route:

Route::resource('posts.comments',CommentController::class)->scoped(
    ['comment'=>'test_id',]
);

 

Controller:

public function store(Request $request)
{
    //
    dd($request->name);
}

 

URL : 127.0.0.1:8000/posts/1/comments

Result: "navid"

 

Route Parameter:

If we want to get the route parameter we have to add additional arguments with request

public function store(Request $request, $id)
{
    //        echo $id;
    dd($request->name);
}

 

By Navid Anjum

Full-stack web developer and founder of Laravelaura. He makes his tutorials as simple as humanly possible and focuses on getting the students to the point where they can build projects independently. https://github.com/NavidAnjum

Leave a Reply

Your email address will not be published. Required fields are marked *