When you view your site, do you see public in the URL?
Requested Resource NOT Found (livewire/message)
Am trying to use livewire in an exsiting Laravel 7. When I type in the input or click submit button i get the following error:
"The requested resource /livewire/message/frontend.view-product was not found on this server."
See code snippets below:
Loading component (ProductsController)
public function viewProduct($product_id)
{
return view('frontend.pages.view-product')->with('product_id',$product_id);
}
Normal blade (Layout)
@extends('frontend.layouts.master')
@section('content')
@livewire('frontend.view-product', ['product_id' => $product_id])
@endsection
Component blade
<form>
<input type="hidden" wire:model="product_id" value="{{ $product->product_id }}">
<input type="hidden" wire:model="product_name" value="{{ $product->product_name }}">
<input type="hidden" wire:model="price" value="{{ $product->price }}">
<input type="text" wire:model="quantity" value="1">
@error('quantity') <span class="text-danger">{{ $message }}</span>@enderror
<button wire:click.prevent="addToCart()" class="btn btn-primary btn-md mr-1 mb-2">
Add To Cart
</button>
<button type="button" class="btn btn-primary btn-md mr-1 mb-2">Add To Wishlist</button>
</form>
<div wire:loading wire:target="addToCart">
<img src="{{ asset('system/img/spinner.gif') }}" alt="Processing...">
</div>
Component
<?php
namespace App\Http\Livewire\Frontend;
use Livewire\Component;
use App\Models\Product;
use DB;
class ViewProduct extends Component
{
public $product_id,$product_name,$price,$quantity,$subtotal;
protected $rules = [
'quantity' => 'required|numeric'
];
public function render()
{
$product=Product::where('product_id',$this->product_id)->first();
$photos=DB::table('product_photos')->where('product_id',$this->product_id)->get();
return view('livewire.frontend.view-product')->with('product',$product)
->withPhotos($photos);
}
/*
* Add to cart
*/
public function addToCart()
{
$this->validate();
$customer_id=Auth::guard('customer')->user()->id;
$subtotal=$this->price * $this->quantity;
$add_to_cart=ShoppingCartModel::create([
"customer_id"=>"$customer_id",
"product_id"=>$this->product_id,
"unit_price"=>$this->price,
"quantity"=>$this->quantity,
"subtotal"=>"$subtotal"
]);
session()->flash('success', $this->product_name.' successfully added to cart!');
}
}
Am new to livewire. Any help on what's happening will be highly appreciated.
Hi @kenprogrammer,
Are you using the local development server that Laravel provides php artisan serve or other? If other, you need to be sure of activate Apache's mod_rewrite or similar.
I was using the built-in server of PHP php -S localhost:80 -t public and I was having the same problem that you. I changed to Laravel local development server and the problem disappeared :) The file server.php is in charge of emulate Apache's mod_rewrite functionality.
Thanks to @geordiejackson for pointing out the issue with the view's path. That was what helped me to realize what was the problem.
Please or to participate in this conversation.