getting 404 modal when I do click event on Laravel livewire

Viewed 1097

I have started using livewire but I can't make it work im using a wire:click to load a form either on create mode or edit mode, but when I did click all I got was some sort of modal with 404 error

this is the livewire component


namespace App\Http\Livewire;

use Livewire\Component;

class Activities extends Component
{
    public $view = 'none';

    public function render()
    {
        return view('livewire.activities');
    }

    public function create_view(){

        $this->view = 'create';

    }

    public function edit(){

        $this->view = 'edit';

    }
}

this is the view


<button wire:click="create_view" class="button-warning">{{ __('Create') }}</button>

@if ($view != 'none')
    <div class="col-span-6">
        @include("livewire.$view")
    </div>
@endif

Edit: I load the view manually and it loads correctly, for example:


@if ($view != 'none')
    <div class="col-span-6">
        @include("livewire.edit")
    </div>
@endif

4 Answers

if like you said this work then you have to check for the $view value. Always that you close the view remember change the property to the default value.

@if ($view != 'none')
    <div class="col-span-6">
        @include("livewire.edit")
    </div>
@endif

I think you might be having a Livewire configuration issue. Check your installation and specifically your asset_url in your config/livewire.php if you have published your config

php artisan livewire:publish --config

The 404 modal should disappear once your config is correct.

If your livewire.php file in config not best config this error should not disappear make asset_url 'asset_url' asset_url => 'http://127.0.0.1:8000' (if you have localhost)

Change your code like this. Because in your code the variable $view will consider part of string. So livewire is searching a page like livewire.$view. But in our case we didn't have like that filename. We have only the view file create. So change as per the code given below. It will work

<button wire:click="create_view" class="button-warning">{{ __('Create') }}</button>

@if ($view != 'none')
    <div class="col-span-6">
        @include('livewire.'.$view)
    </div>
@endif
Related