/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { // Check to see if anime exists, if not then create new anime record $series = Anime::where('url', $request->input('anime_url'))->first(); if ($series === null) { $series = new Anime(); $series->name = $request->input('anime_name'); $series->user_id = Auth::user()->id; $series->image = $request->input('anime_image'); $series->synopsis = $request->input('anime_synopsis'); $series->url = $request->input('anime_url'); $series->save(); } $mp3 = $request->file('track'); $track = new Track(); $track->name = $request->input('name'); $track->user_id = Auth::user()->id; $track->anime_id = $series->id; $track->track = $mp3->getClientOriginalExtension(); $track->save(); if (!$request->hasFile('track')) { return "no file uploaded"; } //Use some method to generate your filename here. Here we are just using the ID of the image $filename = $track->id . "." . $track->track; //Push file to S3 Storage::disk('s3')->put($filename, file_get_contents($mp3)); return redirect()->route('home')->with('status', 'Track Added!'); }
public function insertAnime(Request $request) { $anime = new Anime(); $anime->title = Input::get('title'); $anime->category = Input::get('category'); $destination_path = base_path() . "/image_store/anime_cover"; $filename = $anime->title . '.' . $request->file('image')->getClientOriginalExtension(); $filename = str_replace(' ', '_', $filename); $request->file('image')->move($destination_path, $filename); $anime->cover = url('private/image_store/anime_cover') . "/" . $filename; $anime->studio = Input::get('studio'); $anime->rating = Input::get('rating'); $anime->description = Input::get('description'); $anime->season = Input::get('season'); $anime->save(); return Input::get('category'); }