Home > Enterprise >  laravel error : InvalidArgumentException : Request::capture() in index.php
laravel error : InvalidArgumentException : Request::capture() in index.php

Time:09-27

I want to learn how csrf works. Then, I found the following website. The teaching provided in it is: Add a function to modify the user's name for the laravel dashboard. And this teaching is in the chapter "Set Up Simulated Functionality".

https://www.stackhawk.com/blog/laravel-csrf-protection-guide/

Create a new controller /app/Http/Controllers/UserController.php

<?php
namespace AppHttpControllers;

use AppHttpControllersController;
use IlluminateHttpRequest;
use AppModelsUser;
use IlluminateSupportFacadesSession;

class UserController extends Controller
{
    public function update(Request $request)
    {
        $user = User::findOrFail(auth()->user()->id);
        $user->name = $request->name;
        $user->save();
        Session::flash('message', 'Name updated!');
        return back();
    }
}

update /resources/views/dashboard.blade.php

<x-app-layout>
    <x-slot name="header">
        <h2 >
            {{ __('Dashboard') }}
        </h2>
    </x-slot>

    <div >
        <div >
            <div >
                <div >
                    You're logged in!
                </div>

                {{-- This is the new code block to be added to the file --}}
                @if(Session::has('message'))
                    <div >
                        <p >{{ Session::get('message') }}</p>
                    </div>
                @endif
                <div >
                    <form method="POST" action="/users/">
                        @method('PATCH')
                        <div >
                            <x-input value="{{ auth()->user()->name }}" id="name"  type="text" name="name" placeholder="Your name here" required />
                        </div>
                        <x-button >
                            {{ __('Update Name') }}
                        </x-button>
                    </form>
                </div>
                {{-- End of the new code block --}}
            </div>
        </div>
    </div>
</x-app-layout>

update routes/web.php

//add this to the top of the file
use AppHttpControllersUserController; 

//This goes with the other routes
Route::patch('/users/', [UserController::class, 'update'])->middleware(['auth']);

After I added/modified the following three files according to his teaching...I got such an error message :

InvalidArgumentException
Unable to locate a class or view for component [input].

public/ index.php : 52 require_once

.
.

$app = require_once __DIR__.'/../bootstrap/app.php';

$kernel = $app->make(Kernel::class);

$response = $kernel->handle(
    $request = Request::capture()  // error
)->send();

$kernel->terminate($request, $response);
.
.

In my understanding, the code written by this master is not wrong. In addition, this is a container that uses docker to run, I don't think it should be a version problem. What is the reason for this error? Please how can I fix this error?

CodePudding user response:

The error is in the view /resources/views/dashboard.blade.php,

you don't have any components called <x-input and <x-button, just raplace it with normal html input and button, or create missing blade component

https://laravel.com/docs/9.x/blade#components

  • Related