Level 23
@lmao3d that is a very big question. Suggest you look at documentation and try and then post when you run into issues, but as a starting point. There are a number of approaches in your controller. Use auth in each controller method or the right way middleware - both are ok if you are starting out.
public function saveImage(Request $request)
{
if (auth()->check()) {
if ($request->has("image")) {
$image = $request->image;
return $image->storeAs('images', $image->getClientOriginalExtension());
}
}
return response()->json(['Unauthorized']);
}
public function viewImage($id)
{
if (auth()->check()) {
$image = Image::find($id);
return view('dashboard.main')->with(['image' => $image]);
}
return response()->json(['Unauthorized']);
}
// OR Middlewar
public function __construct()
{
$this->middleware('auth');
}
public function viewImage(Request $request)
{
if ($request->has("image")) {
$image = $request->image;
return $image->storeAs('images', $image->getClientOriginalExtension());
}
}
public function viewImage($id)
{
return view('dashboard.main')->with(['image' => Image::find($id)]);
}