/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Responsequest $request * @return \Illuminate\Http\Response */ public function store(CreateSongRequest $request) { if (!$request->hasFile('song')) { //throw exception? return; } elseif (!$request->file('song')->isValid()) { //throw exception? return; } $user = Auth::user(); $data = $request->all(); $path = 'songs/' . $user->id . '/'; $name = str_random(32); $extension = $request->file('song')->guessExtension(); $extension = $extension = 'mpga' ? '.mp3' : '.' . $extension; //mpga to mp3 $fileName = $name . $extension; if (Storage::put($path . $name . $extension, file_get_contents($request->file('song')->getRealPath()))) { $song = new Song(['user_id' => $user->id, 'file_name' => $fileName, 'name' => $data['name'], 'description' => isset($data['description']) ? $data['description'] : null, 'url' => isset($data['url']) ? $data['url'] : null, 'label' => isset($data['label']) ? $data['label'] : null, 'downloads_enabled' => isset($data['downloads_enabled']) ? true : false, 'comments_enabled' => isset($data['comments_enabled']) ? true : false, 'public' => isset($data['public']) ? true : false, 'license' => isset($data['license']) ? $data['license'] : null, 'released_at' => $data['released_at'], 'file_location' => $path]); if ($song->save()) { if (isset($data['tags']) && $data['tags'] != '') { $tags = explode(',', $data['tags']); $song->tag($tags); } } return redirect('dashboard'); } }
public function postCreate(Request $request) { $this->validate($request, ['title' => 'required|max:100']); $item = new Song(); $item->title = $request->title; $item->lyrics = $request->lyrics; $item->save(); return redirect('/category/songs'); }
public function store(Song $songs) { $songs->title = \Request::get('title'); $songs->lyrics = \Request::get('lyrics'); $songs->slug = \Request::get('slug'); $songs->save(); $file = \Request::file('myname'); $imageName = $songs->slug . '.' . $file->getClientOriginalExtension(); \Request::file('myname')->move(base_path() . '/public/images/catalog/', $imageName); return Redirect('songs'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $data = $request->all(); if (!empty($data) && isset($data['id'])) { $videoId = $data['id']; $song = new Song(); $row = $song->where('video_id', $videoId)->first(); if (is_null($row)) { $submission = new Submission(); $user = \Auth::user(); $latestSong = new Song(); $latestSong = $latestSong->orderby('updated_at', 'desc')->first(); // Add song $song->video_id = $videoId; $song->video_name = $data['name']; $song->video_duration = $data['duration']; $song->created_at = Carbon::now()->addHours(2); if (is_null($latestSong)) { $song->updated_at = $song->created_at; } else { // We want to set the updated_at coorsponding to latest added // song duration, for a consistent playlist. $latestSongUpdateDate = Carbon::parse($latestSong->updated_at)->timestamp; $latestSongDuration = $latestSong->video_duration; $nextUpdateAtStop = $latestSongUpdateDate + $latestSongDuration; $song->updated_at = Carbon::createFromTimestamp($nextUpdateAtStop)->toDateTimeString(); } $song->save(); $submission->facebook_id = $user->facebook_id; $submission->playlist_id = $song->video_id; $submission->save(); // Publish song added $this->pusher->trigger('playlist-channel', 'song-added', []); return new Response(json_encode($song), Response::HTTP_CREATED); } else { // Song record already exists return new Response('Conflict', Response::HTTP_CONFLICT); } } // Request data not supported return new Response('Unprocessable Entity', Response::HTTP_UNPROCESSABLE_ENTITY); }
|-------------------------------------------------------------------------- | | Here is where you will register all of the routes in an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ use App\Song; Route::get('/', function () { return view('welcome'); }); Route::get('songs', function () { ## 1. Variante um einen Datensatz zu erstellen $song = new Song(); $song->titel = 'Pump Up The Jam'; $song->save(); ## 2. Variante direkt ## Achtung im Model muss protected $fillable (white list) oder $guarded (black list) gesetzt sein $noch_ein_song = Song::create(['titel' => 'What a wonderful world']); return Song::all(); //alle songs //return Song::find(1); //song mit id 1 }); ## Anonyme Funktion mit Parametern innerhalb der URL Route::get('/Benutzer/{name}', function ($user) { return 'Hallo ' . $user; }); ## About mit einer einfachen View mit übergebenen Werten Route::get('/About', function () { ## Array Deklaration in vereinfachter Schreibweise seit PHP 5.4 $fw = ['name' => 'Laravel', 'version' => '5.1.11', 'notes' => 'Mein erster Eindruck ist <b>sehr gut</b>!'];
public function store() { if (Auth::check()) { $file = Input::file('url_source'); $file = $this->uploadFile($file); $name = Input::get('name'); $artist_id = Input::get('artist_id'); $user = new Song(); $user->name = $name; $user->artist_id = $artist_id; $user->url_source = $file; $user->save(); return redirect('songs'); } else { return redirect(url()); } }
/** * Update Song attributes. ATM it is just setting whether song is active. */ public function update(Request $request, Song $song) { $song->active = $request->active; $song->save(); }