I am using the livewire image preview temporaryUrl() function
<input wire:model="image" type="file" accept="image/*">
<img class="input-img-preview" src="{{$image->temporaryUrl()}}">
It is working fine when I do the command:
php artisan optimize
But the language routes are turning into 404 error!
And when I use this command:
php artisan optimize:clear
The language routes are working fine but the image preview crashes.
BTW I am using mcamara/laravel-localization
Related
Im working on a e-commerce web-app using laravel. I have a section called shop by brand with the pictures of the brands and when i click on the picture i want it to show me the products of that brand.
This is the blade part of my code where i call the route:
<div class="brand-slides owl-carousel owl-theme">
<div class="brand-item">
<img src="assets/img/brand/shopbybrand1.jpg" alt="image">
</div>
</div>
This is my controller:
public function searchVendor()
{
$searchproduct="Fanola";
$product=product::Where('vendor','LIKE',"%$searchproduct%")->get();
return view('home.userpage',compact('product'));
}
At the moment its just a simple code that will work with the "Fanola" brand only. I did it this way just to test if it works.
And this is my route in my web.php:
Route::get('/searchbybrand', [HomeController::class, 'searchVendor']);
The error it shows me when i serve it is "Route [searchbybrand] not defined."
Ive tried clearing the route cache and it still doesnt work. I asked chat gpt about this and it gave me different ideas like defining the route like this:
Route::get('search-by-brand', 'HomeController#searchVendor')->name('searchbybrand');
When i do it like this it shows a different error: "Target class [HomeController] does not exist."
I also tried composer dump-autoload, php artisan config:clear and php artisan cache:clear as per its suggestions but none of them worked.
this is because your route doesn't have a name you can fix it like this
Route::get('/searchbybrand', [HomeController::class, 'searchVendor'])->name('searchbybrand');
or instead of that in your blade you can use url instead of route
<div class="brand-slides owl-carousel owl-theme">
<div class="brand-item">
<img src="assets/img/brand/shopbybrand1.jpg" alt="image">
</div>
</div>
and for your second problem which says Target class [HomeController] does not exist. add this in top of your web.php
use App\Http\Controllers\HomeController;
also at the end run
php artisan optimize
I have a pretty simple livewire component that helps a user store a vanity URL
<form wire:submit.prevent="save">
<div class="form-group form-inline">
<span>{{ config('app.url') }}/request/</span>
<input type="text" id="vanity" wire:model.defer="vanityUrl" name="vanityUrl">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">#if($saved) Saved #else Save #endif</button>
<button type="button" id="copy-vanity" class="btn btn-secondary">Copy</button>
</div>
</form>
And the save action is pretty simple as well.
public function save()
{
$user = Auth::user();
$this->validate();
$user->update(['vanity_slug' => Str::slug($this->vanityUrl)]);
$this->vanityUrl = Str::slug($this->vanityUrl);
$this->saved = true;
}
This works locally but not in production. I am using Forge, php7.4, L8, its all the same between the environments except the URLs. I have livewire:scripts and livewire:styles loaded, and again it works locally but not in prod.
In prod, the page reloads. I have been trying to figure this out for a couple days now... driving me crazy. TIA
Cached Views
The most typical issue when Livewire isn't working after deploying to a production environment (or for that matter, after setting it up in localhost as well), is that your views, specifically layouts/app.blade.php is cached before the #livewireScripts directive is loaded. This means that it will not render #livewireScripts or #livewireStyles as the component, but will output the literal string.
This is fixed by simply running php artisan optimize:clear, to clear your cache (specifically the view cahce).
Missing Installation of Livewire
However, there are some cases where Livewire is not installed - or not installed properly. You can ensure that Livewire is installed through composer by running composer show -D while in the root directory of your Laravel application. Look for livewire/livewire. If its not there, then install it (see https://laravel-livewire.com/docs/2.x/installation). To install Livewire through composer, run the following command.
composer require livewire/livewire
Using Alpine.js v3 and Livewire v2w
If you have updated to Apline.js v3, you need to use Livewire v2.5 or higher. Simply update your Livewire version.
Faulty Installation of Livewire
The last scenario I've heard of so far with this kind of problem, is that Livewire is installed - but its still not working properly. This is the most uncommon from what I have seen so far. This happens when the scripts that Livewire hooks into is not working as intended (say, a form with wire:submit.prevent="submit" is submitting the actual form instead of sending the AJAX request), but Livewire is installed and #livewireScrtips is rendering as it should. For whatever reason this happens, I'm not sure (as I haven't experienced it first hand), but its quite simple to fix.
The solution for these scenarios is to reinstall Livewire - and you do that by simply removing and require the package again. After the reinstall, its a good idea to clear the cache, just to ensure that the view is not cached without the Livewire-directives.
composer remove livewire/livewire && composer require livewire/livewire && php artisan optimize:clear
I have a blade view file in my project.
The HTML structure is something like :
<div class="a">
<div class="b">
</div>
<div class="c">
</div>
<div>
The problem is that whenever I update anything inside class c, the changes are not rendered.
I have cleared configuration cache as well as view cache as :
php artisan config:clear && php artisan config:cache
php artisan view:clear && php artisan view:cache
This doesn't help either.
Upon further inspection, I found out that, the cache file in /project_root/storage/framework/views is separately kept for a specific part of the page only, in my case the div with class c.
I have no idea how it ended up keeping a separate cache for a small segment of a page. Can anybody suggest me a solution.
EDIT : I have tried deleting the entire cache folder /project_root/storage/framework/views as well in vain.
Other relevant informations :
Hosted server : Nginx on ubuntu
The sendfile option in nginx.conf is ON. If this is relevant.
Some ideas:
clear browser cache
check permissions to storage directory (it should be 777)
be sure that your css is compiled (if you use webpack, laravel mix or gulp or something else)
check if your css is loaded with your changes
change css file name (read about notation main.css?3.4.1 - each time when you make change in css or js it changes value after "?")
After change:
<link rel="stylesheet" href="style.css?v=3.4.2">
And:
<?php $cssVersion = "3.4.2"; ?>
<link rel="stylesheet" href="global.css?v=<?php echo $cssVersion; ?>">
If you use PHP Storm:
open menu File → Settings
go to Deployment → Options section
then uncheck option Preserve files timestamps
Good luck!
It directly show #csrf & #method('PUT') on the page
You may use the #method Blade directive to generate the _method input:
<form action="/foo/bar" method="POST">
#method('PUT')
</form>
These code does not work.
These directives are coming in Laravel 5.6 as it was mentioned by Laravel News.
As I am writing this answer, Laravel 5.6 have not yet been released.
You can do this to install a fresh version of Laravel 5.6:
composer create-project laravel/laravel your-project-name-here dev-develop
I dev laravel 5.4 on windows 10 with xampp (Apache + PHP 5.6.28) and I move my project to MacBook and I using Mamp pro (Apache + PHP 5.6.28).
I have a problem,Can't POST Request all form action.
It's show,
TokenMismatchException
in VerifyCsrfToken.php (line 68)
.....
I try,
Composer update
remove all file in session
php artisan cache:clear
browser clear cache
but can't resolve.
How can I do ?
add csrf token in your form.
<form>
{{ csrf_field() }}
</form>
Here is documentation about csrf protection.
Also you can use laravelcollective forms. They have csrf protection by default. You can easly install this package from here