Professional Documents
Culture Documents
//migrations/authors_table
$table->increments('id');
$table->timestamps();
$table->string('name');
Schema::dropIfExists('authors');
//migrations/quotes_table
$table->increments('id');
$table->timestamps();
$table->text('quote');
$table->integer('author_id');
Schema::dropIfExists('quotes');
//models/author
return $this->hasMany('App\Quote');
//models/quote
return $this->belongsTo('App\Author');
//views/index.blade.php
@extends('layouts.master')
@section('title')
Trending Quotes
@endsection
@section('styles')
@endsection
@section('content')
<section class="quotes">
<article class="quote">
<div class="delete">
<a href="#">x</a>
</div>
Quote Text
</article>
Pagination
</section>
<section class="edit-quote">
<form >
<div class="input-group">
</div>
<div class="input-group">
</div>
</form>
</section>
@endsection
//views/layouts/master.blade.php
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>@yield('title')</title>
@yield('styles')
</head>
<body>
@include('includes.header')
<div class="main">
@yield('content')
</div>
</body>
</html>
//css/main.css
body {
padding : 0;
margin : 0;
font-size : 16px;
line-height: 20px;
.main{
width:80%;
margin:49px auto;
.edit-quote{
text-align: center;
.quotes{
text-align: center;
.quote{
position: relative;
display: inline-block;
width:calc(25% - 48px);
margin:32px;
padding:16px;
vertical-align: top;
background-color: #fff6e0;
.quote.first-in-line{
margin-left: 0;
.quote.last-in-line{
margin-right: 0;
.quote .info{
margin-top:8px;
font-size:12px;
font-family: "Roboto",sans-serif;
color:#ccc;
.quote .info a{
color : #ccc;
color : #aaa;
}
.quote .delete{
position: absolute;
top : 0px;
right: 4px;
font-family: sans-serif;
//views/index
//quotecontroller
$quotes = Quote::all();
return view('index',compact('quotes'));
$authorText = ucfirst($request['author']);
$quoteText = $request->quote;
$author = Author::where('name',$authorText)->first();
if(!$author){
$author->name = $authorText;
$author->save();
$author->quotes()->save($quote);
//routes/web.php
Route::post('/new',[
]);
//index.blade.php
@section('content')
<section class="quotes">
@for($i=0; $i<count($quotes);$i++)
<article class="quote">
<div class="delete">
<a href="#">x</a>
</div>
{{ $quotes[$i]->quote }}
</article>
@endfor
<div class="pagination">
Pagination
</div>
</section>
//quotecontroller/postquote
$this->validate($request,[
]);
//index.blade.php
@section('content')
@if(count($errors) > 0)
<ul>
@foreach($errors->all() as $error)
{{ $error }}
@endforeach
</ul>
</section>
@endif
@if( Session::has('success') )
{{ Session::get('success')}}
</section>
@endif
<section class="quotes">
//index.blade.php
<div class="delete">
- <a href="#">x</a>
</div>
//routes
Route::get('/delete/{quote_id}',[
]);
//quotecontroller
$quote = Quote::find($quote_id);
$author_deleted = false;
dd($quote->author);
//$test = $quote->author()->get();
$test = $quote->author->id;
//dd($test);
$quote->author->delete();
$author_deleted = true;
$quote->delete();
//quotecontroller
if(!is_null($author)){
$quote_author = Author::where('name',$author)->first();
if($quote_author){
$quotes = $quote_author->quotes()->orderBy('created_at','desc')->get();
else{
$quotes = Quote::orderBy('created_at','desc')->get();
//index.blade.php
@section('content')
@if( !empty(Request::segment(1)))
<section class="filter-bar">
</section>
@endif
Route::get('/{author?}',[
]);
//quotecontroller
- $quotes = $quote_author->quotes()->orderBy('created_at','desc')->get();
+ $quotes = $quote_author->quotes()->orderBy('created_at','desc')->paginate(6);
- $quotes = Quote::orderBy('created_at','desc')->get();
+ $quotes = Quote::orderBy('created_at','desc')->paginate(6);
//index.blade
<div class="pagination">
<center>{{$quotes->links()}}</center>
</div>
@endsection