Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- // use App\Http\Requests;
- use App\AuthorModel;
- use App\QuoteModel;
- class QuoteController extends Controller
- {
- public function getIndex()
- {
- $quotes = QuoteModel::all();
- return view('index' ,[
- 'quotes' => $quotes
- ]);
- }
- public function postQuote(Request $request)
- {
- $authorText = ucfirst($request['author']);
- $quoteText = $request['quote'];
- $theAuthor = AuthorModel::where('name', $authorText)->first();
- if(!$theAuthor){
- $theAuthor = new AuthorModel();
- $theAuthor->name = $authorText;
- $theAuthor->save();
- }
- $theQuote = new QuoteModel();
- $theQuote->quote = $quoteText;
- $theAuthor->quotes()->save($theQuote);
- return redirect()->route('index')->with([
- 'success' => 'Quote saved!'
- ]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement