public function run() { Quote::create(['teks' => 'Success is going from failure to failure without losing your enthusiasm', 'author' => 'Winston Churchill', 'background' => '1.jpg']); Quote::create(['teks' => 'Dream big and dare to fail', 'author' => 'Norman Vaughan', 'background' => '2.jpg']); Quote::create(['teks' => 'It does not matter how slowly you go as long as you do not stop', 'author' => 'Confucius', 'background' => '3.jpg']); //... add more quotes if you want! }
/** * Process and store a quote. * @param \App\Http\Requests\QuoteRequest $request * @return string */ public function store(QuoteRequest $request) { // Require ajax $this->requireAjax($request); // Create the quote Quote::create($request->stripped('culprit', 'quote') + ['date' => Carbon::createFromFormat("Y-m-d H:i:s", $request->get('date'), env('SERVER_TIMEZONE', 'UTC'))->tz('UTC'), 'added_by' => $this->user->id]); Flash::success('Quote created'); return ['success' => true]; }
/** * Run the database seeds. * * @return void */ public function run() { HTTPRequest::verifyPeer(env('UNIREST_VERIFYPEER')); //Get 10 quotes, from a Mashape API for ($i = 0; $i < 10; $i++) { $response = HTTPRequest::post("https://andruxnet-random-famous-quotes.p.mashape.com/cat=famous", array("X-Mashape-Key" => env('MASHAPE_KEY'), "Content-Type" => "application/x-www-form-urlencoded", "Accept" => "application/json")); Quote::create(["content" => $response->body->quote, "author" => $response->body->author, "source" => "https://andruxnet-random-famous-quotes.p.mashape.com/cat=famous"]); } }
/** * Save */ public function save($quote = null, $data = null) { DB::transaction(function () use(&$data, &$quote) { if (is_null($quote)) { $quote = Quote::create($data); } else { $quote->fill($data)->save(); } if (!$data['items']) { throw new UnprocessableEntityHttpException('Empty line items'); } $quote->items()->delete(); foreach ($data['items'] as $item) { $quote->items()->create($item); } }); return $this->getById($quote->id); }
/** * Store a newly created resource in storage. * * @param QuoteRequest $request * * @return Response */ public function store(QuoteRequest $request) { $quote = Quote::create($request->all()); flash()->success("Quote has been successfully created!"); return redirect()->route('admin.quotes.edit', $quote)->withInput(); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(StoreQuotePostRequest $req) { // passing as assoc array to Quote model to insert a record $quote = Quote::create($req->only('quote', 'author', 'image')); return response()->json($quote, 200); }