Esempio n. 1
0
 public function tweetBin(Bin $bin)
 {
     $status = 'Bin: #laravel ' . $bin->url() . ' ' . $bin->title;
     Twitter::postTweet(['status' => str_limit($status, 135), 'format' => 'json']);
     $bin->tweeted = true;
     $bin->save();
     session()->flash('success', 'Bin has successfully been tweeted!');
     return redirect()->back();
 }
Esempio n. 2
0
 public function show($username)
 {
     $user = User::where('username', $username)->first();
     if (!$user) {
         session()->flash('error', 'We cannot find a user with the username of [ <b>' . $username . '</b> ] Sorry.');
         return redirect()->route('home');
     }
     $bins = Bin::publicOnly()->where('user_id', $user->id)->orderBy('updated_at', 'DESC')->paginate(8);
     return view('user.show', compact('user', 'bins'));
 }
Esempio n. 3
0
 private static function canViewPrivateBin(Bin $bin, $request)
 {
     // Check if user is admin
     if (auth()->check() && auth()->user()->admin()) {
         return true;
     }
     // Check if user is bin owner
     if (auth()->check() && auth()->user()->getAuthIdentifier() == $bin->user_id) {
         return true;
     }
     if ($bin->isShared()) {
         if (session()->get('private-' . $bin->getRouteKey()) == $bin->private_hash) {
             return true;
         }
         // Check if user has a hash key for bin
         $hash = $request->route('hash');
         if ($hash) {
             if ($bin->private_hash == $hash) {
                 if (!session()->has('private-' . $bin->getRouteKey()) || session()->get('private-' . $bin->getRouteKey()) !== $bin->private_hash) {
                     session(['private-' . $bin->getRouteKey() => $bin->private_hash]);
                 }
                 return true;
             }
         }
     }
     return false;
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     $router->bind('bin', function ($value) {
         $id = hashid()->decode($value);
         if (empty($id)) {
             $id = null;
         } else {
             $id = $id[0];
         }
         return Bin::where('id', $id)->first();
     });
     $router->bind('comment', function ($value) {
         $id = hashid()->decode($value);
         if (empty($id)) {
             $id = null;
         } else {
             $id = $id[0];
         }
         return Comment::where('id', $id)->first();
     });
     parent::boot($router);
 }
Esempio n. 5
0
    public function index()
    {
        $sample = '<?php


class Idea extends Eloquent
{

    /**
     * Dreaming of something more?
     *
     * @with  Laravel
     */
     public function create()
     {
        // Have a fresh start...
     }

}';
        $artisans = User::verifiedOnly()->count();
        $bins = Bin::publicOnly()->count();
        $files = Snippet::publicOnly()->count();
        return view('home', compact('sample', 'artisans', 'bins', 'files'));
    }
Esempio n. 6
0
 public function deletePost(Bin $bin, Comment $comment)
 {
     $comment->delete();
     session()->flash('success', 'Comment deleted successfully!');
     return redirect()->route('bin.code', $bin->getRouteKey());
 }
Esempio n. 7
0
 public function deletePost(Bin $bin, Requests\Bins\DeleteBin $request)
 {
     $bin->delete();
     session()->flash('success', 'Your bin has been deleted!');
     return redirect()->route('bins.my');
 }