<?php
class RegisteredUserController extends Controller
{
public function store(*Request $request*): RedirectResponse
{
$request->validate([
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'lowercase', 'email:strict,dns', 'max:255', 'unique:' . User::class],
'password' => ['required', 'confirmed', Rules\Password::defaults()],
'profile' => ['required', 'image', 'mimes:jpeg,png', 'max:2048'],
], [
'profile.max' => 'The profile image must not be larger than 2MB.',
]);
if ($request->hasFile('profile')) {
$profilePath = $request->file('profile')->store('profiles', 'public');
}
$user = User::create([
'name' => $request->name,
'email' => $request->email,
'password' => Hash::make($request->password),
'profile' => $profilePath,
]);
event(new Registered($user));
Auth::login($user);
return redirect(route('dashboard', absolute: false));
}
}
example profile value in user:
profiles/CKyXwwZFVGJ5ghhkfUBQfXDsMgw4eliC2iz8YFLN.jpg
why i can do thses 3 without even php artisan storage:link and they still works, i can still see the image?:
<img src="{{ auth()->user()->profile }}" />
<img src="{{ asset(auth()->user()->profile) }}" />
<img src="{{ asset('storage/' . auth()->user()->profile) }}" />
the image is stored in the `storage/app/public/profiles/filename.jpg' (note that i haven't symlink it yet and i haven't configure the filesystems.php)