Laravel menyimpan foto di kedua dan database
public function store(StorePostRequest $request)
{
$request->validate([
//unique:table,column
"title" => "required|unique:posts,title|min:5",
"description" => "required|min:15",
"cover" => "required|file|mimes:jpeg,png|max:5000"
]);
//photo Save in local
$newName = "cover_".uniqid()."_".$request->file('cover')->extension();
$request->file('cover')->storeAs("public/cover",$newName);
//store in database
$post = new Post();
$post->title = $request->title;
$post->slug = Str::slug($request->title);
$post->description = $request->description;
$post->excerpt = Str::words($request->description,50);
$post->cover = $newName;
$post->user_id = Auth::id();
$post->save();
return redirect()->route("index")->with('status','Post Created');
return $request;
}
WinMaw