Example #1
0
 /**
  * Responds to requests to POST /landmark/create
  */
 public function postCreate(Request $request)
 {
     if (\App\Landmark::where('name', '=', $request->name)->exists()) {
         \Session::flash('flash_message', 'A Landmark with that name already exists.');
         return redirect('\\landmarks');
     }
     $this->validate($request, ['name' => 'required|min:5', 'description' => 'required|min:1', 'location' => 'required|min:1', 'filepath' => 'required|url', 'photo_description' => 'required|min:1']);
     # Enter landmark and its photo into the database
     $landmark = new \App\Landmark();
     $landmark->name = $request->name;
     $landmark->description = $request->description;
     $landmark->location = $request->location;
     $landmark->user_id = \Auth::id();
     # <--- NEW LINE
     $landmark->save();
     $photo = new \App\Photo();
     $photo->filepath = $request->filepath;
     $photo->photo_description = $request->photo_description;
     $photo->landmark_id = $landmark->id;
     $photo->user_id = \Auth::id();
     $photo->save();
     # Add the tags
     $request->tags;
     if ($request->tags) {
         $tags = $request->tags;
     } else {
         $tags = [];
     }
     $landmark->tags()->sync($tags);
     # Done
     \Session::flash('flash_message', 'Your landmark was added!');
     return redirect('/landmarks');
 }
 public function create(Request $request)
 {
     $user = new \App\User();
     $user->username = $request->username;
     $user->password = Hash::make($request->password);
     $user->email = $request->email;
     $user->firstname = $request->firstname;
     $user->middlename = $request->middlename;
     $user->lastname = $request->lastname;
     $user->permission()->associate(\App\Permission::find($request->permission_id));
     $user->save();
     $photo = new \App\Photo();
     $photo->path = 'default_user_thumbnail.png';
     $photo->user()->associate($user);
     $photo->save();
     return $user ? true : false;
 }
Example #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);
 }
Example #4
0
| it contains. The "web" middleware group is defined in your HTTP
| kernel and includes session state, CSRF protection, and more.
|
*/
Route::group(['middleware' => ['web', 'fw-block-bl']], function () {
    /**
     * Landing Page
     */
    Route::get('/', ['as' => 'welcome', function () {
        $news = App\News::whereType(0)->latest()->first();
        $event = App\Event::latest()->first();
        $codewars = App\CodeWarQuestion::latest()->limit(3)->get();
        $questions = App\Question::wherePublic(1)->approved()->latest()->limit(3)->get();
        $aluminis = App\Alumini::where('speech', '!=', 'null')->get()->random(2);
        $users = App\User::whereBanned(0)->latest()->limit(3)->get();
        $picture = App\Photo::whereGallery(1)->get()->random();
        $technews = App\News::whereType(1)->latest()->first();
        $qotd = App\Quote::getQotd();
        $shouts = App\Shout::limit(15)->latest()->get();
        $shouts = $shouts->sortBy('created_at');
        $urls = ['http://numbersapi.com/random/', 'http://numbersapi.com/random/year/', 'http://numbersapi.com/random/date'];
        try {
            $didyouknow = file_get_contents($urls[array_rand($urls)]);
        } catch (Exception $e) {
            $didyouknow = "This website is hosted on a VPS with 1GB of RAM and is developed using PHP as backend, MySQL & Redis for database storage, and Sockets for real time events.";
        }
        $data = ['news' => $news, 'event' => $event, 'aluminis' => $aluminis, 'codewars' => $codewars, 'questions' => $questions, 'users' => $users, 'picture' => $picture, 'technews' => $technews, 'qotd' => $qotd, 'shouts' => $shouts, 'didyouknow' => $didyouknow];
        return view('welcome', $data);
    }]);
    /**
     * Coming Soon Page
Example #5
0
 public function updateProfile()
 {
     $user = \Auth::user();
     if ($user == null) {
         return redirect('home');
     }
     $input = Request::all();
     // Validation
     $v = Validator::make($input, ['first_name' => 'max:50', 'last_name' => 'max:50', 'name' => 'required|max:50|alpha_dash|unique:users,name,' . $user['id'], 'birthday' => 'required|date_format:Y-m-d', 'country' => 'max:50', 'city' => 'max:50', 'occupation' => 'max:50', 'skype_id' => 'min:6|max:32|alpha_num|unique:users,skype_id,' . $user['id'], 'btc_address' => 'min:26|max:35|alpha_num|unique:users,btc_address,' . $user['id'], 'profile_photo' => 'image|max:25000']);
     if ($v->fails()) {
         return redirect()->back()->withErrors($v->errors());
     }
     $user->update($input);
     if (!empty($input['profile_photo'])) {
         // Save Photos
         $fileName = time() . '_' . $input['profile_photo']->getClientOriginalName();
         $extension = $input['profile_photo']->getClientOriginalExtension();
         $user_id = $user['id'];
         $image = \Image::make(Request::file('profile_photo'));
         $image->backup();
         $imageTypes = array_keys(config('user_image'));
         foreach ($imageTypes as $imageType) {
             $path = user_photos_path($imageType);
             \File::exists($path) or \File::makeDirectory($path, 0775, true);
             if ($imageType == 'original') {
                 $height = $image->height();
                 $width = $image->width();
             } else {
                 $height = config('user_image' . '.' . $imageType)['height'];
                 $width = config('user_image' . '.' . $imageType)['width'];
                 $image->resize($height, $width);
             }
             $image->save($path . $fileName);
             $image->reset();
             // store this path in photos table
             $photo = new \App\Photo();
             $photo['user_id'] = $user_id;
             $photo['type'] = $imageType;
             $photo['name'] = $fileName;
             $photo['height'] = $height;
             $photo['width'] = $width;
             $photo['extension'] = $extension;
             $photo->save();
         }
     }
     \Session::flash("flash_message", "Your profile has been updated !!!");
     return redirect('users');
 }
Example #6
0
Route::post('auth/register', 'Auth\\AuthController@postRegister');
// FRIENDSHIP ROUTES
Route::get('user/{user}/addFriend', ['as' => 'addFriend', 'uses' => 'UserController@addFriend']);
Route::get('friend/{user}/approveFriend', ['as' => 'approveFriend', 'uses' => 'FriendController@approveFriend']);
Route::get('friend/{user}/denyFriend', ['as' => 'denyFriend', 'uses' => 'FriendController@denyFriend']);
// RESOURCE ROUTES...
Route::resource('user', 'UserController', ['except' => ['create', 'store']]);
Route::resource('blog', 'BlogController', ['except' => ['create', 'delete', 'store']]);
Route::resource('blog.blogPost', 'BlogPostController');
Route::get('/blogPost', ['uses' => 'BlogPostController@index', 'as' => 'blogPosts.index']);
Route::resource('blog.blogPost.photo', 'PhotoController', ['except' => ['index', 'show', 'create']]);
Route::get('/', ['uses' => 'PagesController@index']);
// ROUTE MODEL BINDINGS...
Route::bind('user', function ($value) {
    return App\User::with('blog')->findOrFail($value);
});
Route::bind('blog', function ($value) {
    // de-hyphenate the blog name
    $value = getNameForThisUrl($value);
    // return the Blog instance with the name of $value, with blogPosts
    return App\Blog::with('blogPost')->where('name', $value)->firstOrFail();
});
Route::bind('blogPost', function ($value) {
    // de-hyphenate the blog name
    $value = getNameForThisUrl($value);
    // return the Blog instance with the name of $value, with blogPosts
    return App\BlogPost::with('photo')->where('title', $value)->firstOrFail();
});
Route::bind('photo', function ($value) {
    return App\Photo::findOrFail($value);
});
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| 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('/', function () {
    /*
     # Polymorphic Relationship Example
     # Photo, Staff, Order Models
     #
    */
    $photo = App\Photo::find(3);
    /* You Can Check ID [ 1,2,3,4 ] */
    $imageable = $photo->imageable;
    return $imageable;
});
Route::get('/many-to-many-polymorphic', function () {
    $posts = App\Post::find(1);
    //
    return $posts->tags;
    $vieos = App\Video::find(1);
    //    return $vieos->tags;
    $tags = App\Tag::find(2);
    //    return $tags->posts;
    foreach ($tags->posts as $post) {
        echo $post->pivot->tag_id;
    }