Http request In Laravel and the form data

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);
}

 

Leave a Comment

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

Scroll to Top