i wrote this controller :
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
class cachecompanyController extends Controller
{
public function index()
{
return view('livewire.cache');
}
public function updatecache($id, Request $request){
$validatedata = $request->validate([
'cache'=> ['nullable', 'mimes:jpg,jpeg,png', 'max:2048'],
],
);
$user = User::find($id);
if($request->hasFile('cache')){
$user_img = $request->file('storage/cache');
$name_gen = hexdec(uniqid());
$image_ext = strtolower($user_img->getClientOriginalExtension());
$image_name = $name_gen . '.' . $image_ext;
$up_location = '/cache/';
$last_img = $up_location . $image_name ;
$user_img->move($up_location,$image_name);
$user->cache_photo_path = $last_img;
// dd("lightning");
}
$user->save();
}
}
with these routes :
Route::get('cache-upload', [cachecompanyController::class, 'index'])-> Name('indexcache');
Route::post('/save-cache/{id}',[cachecompanyController::class, 'updatecache'])-> Name('updatecache');
and this layout:
<form method="POST" action="{{ url('save-cache/'.$id = auth()->user()) }}"enctype="multipart/form-data">
<div>
<input type="file" name="cache">
<img class="image rounded-circle" name="cache" src="{{asset('/cache/')}}" alt="cache_photo_path">
<input type="submit" value="Save" >
</div>
</form>
, but when i upload it gives an empty page (error 404) and a link like this :
http://127.0.0.1:8000/save-cache/%7B%22id%22:1,%22name%22:%22Vitamedic%22,%22email%22:%[email protected]%22,%22email_verified_at%22:null,%22current_team_id%22:1,%22profile_photo_path%22:%22profile-photos//n0TdjG3WXfJYDzxJBRcOaoRLIco0rBTdzPCvDYNi.png%22,%22cache_photo_path%22:null,%22companie_photo_path%22:null,%22created_at%22:%222021-11-21T20:55:17.000000Z%22,%22updated_at%22:%222021-11-24T13:30:18.000000Z%22,%22profile_photo_url%22:%22//storage//profile-photos//n0TdjG3WXfJYDzxJBRcOaoRLIco0rBTdzPCvDYNi.png%22%7D
what can I do to fix it ?
My Answer:
help you with PHP programming. Just let me know what you need assistance with!
Rate this post
4 of 5 based on 9320 votesComments