Пример #1
0
 /**
  * Store a newly created song in storage.
  *
  * @return Response
  */
 public function store()
 {
     // Set rules for validator
     $rules = array("artist" => "required", "title" => "required", "requester" => "required", "link" => "required|url");
     // Validate input
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         // TODO: Remember form input...
         return Redirect::to('song/create')->withErrors($validator, "song");
     }
     // Create new song
     $song = Input::all();
     // Set or unset remember cookie
     if (isset($song['remember-requester'])) {
         $cookie = Cookie::make("requester", $song['requester']);
     } else {
         $cookie = Cookie::forget("requester");
     }
     $artist = DB::getPdo()->quote($song['artist']);
     $title = DB::getPdo()->quote($song['title']);
     if (Song::whereRaw("LOWER(artist) = LOWER({$artist}) AND LOWER(title) = LOWER({$title})")->count() > 0) {
         return Redirect::to('song/create')->with('error', "HEBBEN WE AL!!!")->withCookie($cookie);
     }
     Song::create($song);
     // Set success message
     $msg = "Gefeliciteerd! Je nummer is aangevraagd :D";
     // Redirect to song index page with message and cookie
     return Redirect::to("/")->with("success", $msg)->withCookie($cookie);
 }
Пример #2
0
<?php

//ini_set("display_errors", 1);
require __DIR__ . '/autoload.php';
//create new Songs
$model = new Song();
$model->status = 2;
$model->rate = 66;
$model->save(3);
$model = new Song(['title' => 'I can teach you', 'artist' => 'bon jovi', 'status' => 1]);
$model->create();