Exemplo n.º 1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     # First, create an array of all the landmarks we want to associate tags with
     # The *key* will be the landmark id, and the *value* will be an array of tags.
     $landmarks = ['1' => ['bridge', 'metallic', 'large', 'scenic'], '2' => ['ethnic', 'Chinese', 'gate', 'large'], '3' => ['statue', 'Harvard', 'academic', 'metallic']];
     # Now loop through the above array, creating a new pivot for each book to tag
     foreach ($landmarks as $landmark => $tags) {
         # First get the landmark
         $landmark = \App\Landmark::where('id', 'like', $landmark)->first();
         # Now loop through each tag for this landmark, adding the pivot
         foreach ($tags as $tagName) {
             $tag = \App\Tag::where('tag', 'LIKE', $tagName)->first();
             # Connect this tag to this book
             $landmark->tags()->save($tag);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Responds to requests to POST /reviews/{id}/create
  */
 public function postCreate(Request $request, $id = null)
 {
     $landmark = \App\Landmark::find($id);
     if (is_null($landmark)) {
         \Session::flash('flash_message', 'Landmark not found.');
         return redirect('\\landmarks');
     }
     $this->validate($request, ['review' => 'required|min:1']);
     # Enter review
     $review = new \App\Review();
     $review->landmark()->associate($landmark->id);
     $review->user()->associate(\Auth::id());
     # <--- NEW LINE
     $review->review = $request->review;
     $review->save();
     # Done
     \Session::flash('flash_message', 'Your review was added!');
     return redirect('/reviews');
 }
Exemplo n.º 3
0
 /**
  * Responds to requests to POST /photos/{id}/create
  */
 public function postCreate(Request $request, $id = null)
 {
     $landmark = \App\Landmark::find($id);
     if (is_null($landmark)) {
         \Session::flash('flash_message', 'Landmark not found.');
         return redirect('\\landmarks');
     }
     if (\App\Photo::where('filepath', '=', $request->filepath)->exists()) {
         \Session::flash('flash_message', 'A Photo with that URL already exists in our database.');
         return redirect('/photos/' . $id);
     }
     $this->validate($request, ['filepath' => 'required|url', 'photo_description' => 'required|min:1']);
     # Enter photo
     $photo = new \App\Photo();
     $photo->landmark()->associate($landmark->id);
     $photo->user()->associate(\Auth::id());
     # <--- NEW LINE
     $photo->filepath = $request->filepath;
     $photo->photo_description = $request->photo_description;
     $photo->save();
     # Done
     \Session::flash('flash_message', 'Your photo was added!');
     return redirect('/photos/' . $id);
 }
Exemplo n.º 4
0
 /**
  *
  */
 public function getDoDelete($landmark_id)
 {
     $landmark = \App\Landmark::find($landmark_id);
     if (is_null($landmark)) {
         \Session::flash('flash_message', 'Landmark not found.');
         return redirect('\\landmarks');
     }
     if ($landmark->tags()) {
         $landmark->tags()->detach();
     }
     $landmark->delete();
     \Session::flash('flash_message', $landmark->name . ' was deleted.');
     return redirect('/landmarks');
 }
Exemplo n.º 5
0
<!doctype html>
<html>

@extends('layouts.master')


@section('title')
    <title>Show All Landmarks</title>
@stop

@section('content')
    <div class="container">
        <h1>Here are all the landmarks on the site:</h1>

        <?php 
$landmarks = \App\Landmark::orderBy('name')->get();
?>
        @foreach($landmarks as $landmark)
            <div style="text-align: center" class="user_results_container">
                <h2>{{ $landmark->name }}</h2>
                <a href='show/{{$landmark->id}}'>About</a> |
                <a href='/photos/{{$landmark->id}}'>Photos</a>
                <br>
                @if(Auth::check())
                    <a href='/reviews/{{$landmark->id}}/create'>Write Review</a></li> |
                    <a href='/photos/{{$landmark->id}}/create'>Upload Photos</a></li>
                @endif
                <br>
                <div class="outer">
                    <?php 
$photos = \App\Photo::where('landmark_id', '=', $landmark->id)->orderBy(DB::raw('RAND()'))->take(1)->get();
Exemplo n.º 6
0
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for 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.
|
*/
Route::get('/', 'WelcomeController@getIndex');
if (App::environment('local')) {
    Route::get('/drop', function () {
        DB::statement('DROP database yolo');
        DB::statement('CREATE database yolo');
        return 'Dropped yolo; created yolo.';
    });
    Route::get('/workspace', function () {
        $landmark = \App\Landmark::find(1);
        $tags = $landmark->tags;
        dd($tags);
    });
    Route::get('/debug', function () {
        echo '<pre>';
        echo '<h1>Environment</h1>';
        echo App::environment() . '</h1>';
        echo '<h1>Debugging?</h1>';
        if (config('app.debug')) {
            echo "Yes";
        } else {
            echo "No";
        }
        echo '<h1>Database Config</h1>';
        /*