<file_sep><?php

use Illuminate\Database\Seeder;
use Faker\Factory as Faker;
use App\Invoice;
use App\Product;

class InvoiceItemsTableSeeder extends Seeder
{
	/**
	 * Run the database seeds.
	 *
	 * @return void
	 */
	public function run()
	{
		$faker = Faker::create();

		// following line retrieve all the invoice_ids from DB
		$invoices = Invoice::all()->pluck('id');
		// following line retrieve all the product_ids from DB
		$products = Product::all()->pluck('id');

		foreach (range(1,90) as $index) {

			$quantity =  $faker->numberBetween($min = 1, $max = 5);
			$price =  $faker->numberBetween($min = 100, $max = 1000);

			DB::table('invoiceItems')->insert([
				'invoice_id' => $faker->randomElement($invoices),
				'product_id' => $faker->randomElement($products),
				'quantity' => $quantity,
				'price' => $price,
				'total' => ($quantity * $price)
			]);
		}
	}
}
<file_sep><?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Auth;

class Comment extends Model
{

	protected $fillable = [];

	public function commentable()
	{
		return $this->morphTo();
	}

	public function post()
	{
		return $this->belongsTo('App\Post');
	}

   public function user()
   {
      return $this->belongsTo('App\User');
   }

	public function recipe()
	{
		return $this->belongsTo('App\Recipe');
	}

	public function scopeNewComments($query)
   {
      return $query
         ->where('created_at', '>=' , Auth::user()->last_login_date)
         //->where('user_id', '=', Auth::user()->id)
         //->orderBy('title','DESC')
         ;
   }
}
<file_sep><?php

namespace App\Http\Controllers\Backend;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Profile;
use App\Role;
use App\User;
use Auth;
use DB;
use Hash;
use Session;

use App\Http\Requests\CreateUserRequest;
use App\Http\Requests\UpdateUserRequest;
//use App\Http\Requests\UpdateUserPWDRequest;

class UsersController extends Controller
{

##################################################################################################################
#  ██████╗ ██████╗ ███╗   ██╗███████╗████████╗██████╗ ██╗   ██╗ ██████╗████████╗
# ██╔════╝██╔═══██╗████╗  ██║██╔════╝╚══██╔══╝██╔══██╗██║   ██║██╔════╝╚══██╔══╝
# ██║     ██║   ██║██╔██╗ ██║███████╗   ██║   ██████╔╝██║   ██║██║        ██║   
# ██║     ██║   ██║██║╚██╗██║╚════██║   ██║   ██╔══██╗██║   ██║██║        ██║   
# ╚██████╗╚██████╔╝██║ ╚████║███████║   ██║   ██║  ██║╚██████╔╝╚██████╗   ██║   
#  ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝  ╚═════╝   ╚═╝   
##################################################################################################################
	public function __construct() {
		// only allow authenticated users to access these pages
		//$this->middleware('auth', ['except'=>['index','show']]);
		// changing auth to guest would only allow guests to access these pages
		// you can also restrict the actions by adding ['except' => 'name_of_action'] at the end
		$this->middleware('auth');

		//Log::useFiles(storage_path().'/logs/articles.log');
		//Log::useFiles(storage_path().'/logs/audits.log');
	}


##################################################################################################################
# ██╗███╗   ██╗██████╗ ███████╗██╗  ██╗
# ██║████╗  ██║██╔══██╗██╔════╝╚██╗██╔╝
# ██║██╔██╗ ██║██║  ██║█████╗   ╚███╔╝ 
# ██║██║╚██╗██║██║  ██║██╔══╝   ██╔██╗ 
# ██║██║ ╚████║██████╔╝███████╗██╔╝ ██╗
# ╚═╝╚═╝  ╚═══╝╚═════╝ ╚══════╝╚═╝  ╚═╝
// Display a list of resources
##################################################################################################################
	public function index(Request $request, $key=null)
	{
		// if(!checkACL('guest')) {
		//     return view('errors.403');
		// }

		//$alphas = range('A', 'Z');
		$alphas = DB::table('users')
			->select(DB::raw('DISTINCT LEFT(username, 1) as letter'))
			//->where('published_at','<', Carbon::Now())
			//->where('deleted_at','=', Null)
			->orderBy('letter')
			->get();

		$letters = [];
		foreach($alphas as $alpha) {
		  $letters[] = $alpha->letter;
		}

		// If $key value is passed
		if ($key) {
			$users = User::with('role','profile')
				->where('username', 'like', $key . '%')
				->orderBy('username', 'asc')
				->get();
			return view('backend.users.index', compact('users','letters'));
		}

		// No $key value is passed
		$users = User::with('role','profile')->get();
		return view('backend.users.index', compact('users','letters'));
	}


##################################################################################################################
#  ██████╗██████╗ ███████╗ █████╗ ████████╗███████╗
# ██╔════╝██╔══██╗██╔════╝██╔══██╗╚══██╔══╝██╔════╝
# ██║     ██████╔╝█████╗  ███████║   ██║   █████╗  
# ██║     ██╔══██╗██╔══╝  ██╔══██║   ██║   ██╔══╝  
# ╚██████╗██║  ██║███████╗██║  ██║   ██║   ███████╗
#  ╚═════╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝   ╚═╝   ╚══════╝
// Show the form for creating a new resource
##################################################################################################################
	public function create()
	{
		$roles = Role::where('id','<=',70)->orderBy('id','desc')->pluck('display_name','id');

		return view('backend.users.create', compact('roles'));
	}


##################################################################################################################
# ███████╗████████╗ ██████╗ ██████╗ ███████╗
# ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
# ███████╗   ██║   ██║   ██║██████╔╝█████╗  
# ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝  
# ███████║   ██║   ╚██████╔╝██║  ██║███████╗
# ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
// Store a newly created resource in storage
##################################################################################################################
	public function store(CreateUserRequest $request)
	{
		// $input = $request->all();
		// $input['password'] = <PASSWORD>($input['password']);

		// $user = User::create($input);

		// Session::flash('success','User created successfully!');
		// return redirect()->route('backend.users.index');

		$user = new User;
			$user->username				= $request->username;
			$user->email					= $request->email;
			$user->role_id					= $request->role_id;
			$user->password				= <PASSWORD>($request['<PASSWORD>']);
		$user->save();

		$user->profile()->save(new Profile);

		Session::flash('success','User created successfully!');
		return redirect()->route('backend.users.index');


	}


##################################################################################################################
# ███████╗██╗  ██╗ ██████╗ ██╗    ██╗
# ██╔════╝██║  ██║██╔═══██╗██║    ██║
# ███████╗███████║██║   ██║██║ █╗ ██║
# ╚════██║██╔══██║██║   ██║██║███╗██║
# ███████║██║  ██║╚██████╔╝╚███╔███╔╝
# ╚══════╝╚═╝  ╚═╝ ╚═════╝  ╚══╝╚══╝ 
// Display the specified resource
##################################################################################################################
	public function show($id)
	{
		$user = User::findOrFail($id);

		return view('backend.users.show', compact('user'));
	}


##################################################################################################################
# ███████╗██████╗ ██╗████████╗
# ██╔════╝██╔══██╗██║╚══██╔══╝
# █████╗  ██║  ██║██║   ██║   
# ██╔══╝  ██║  ██║██║   ██║   
# ███████╗██████╔╝██║   ██║   
# ╚══════╝╚═════╝ ╚═╝   ╚═╝   
// Show the form for editing the specified resource
##################################################################################################################
	public function edit($id)
	{
		$user = User::findOrFail($id);
		$roles = Role::where('id','<=',70)->orderBy('id','desc')->pluck('display_name','id');

		return view('backend.users.edit', compact('user','roles'));
	}


##################################################################################################################
# ██╗   ██╗██████╗ ██████╗  █████╗ ████████╗███████╗
# ██║   ██║██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██╔════╝
# ██║   ██║██████╔╝██║  ██║███████║   ██║   █████╗  
# ██║   ██║██╔═══╝ ██║  ██║██╔══██║   ██║   ██╔══╝  
# ╚██████╔╝██║     ██████╔╝██║  ██║   ██║   ███████╗
#  ╚═════╝ ╚═╝     ╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚══════╝
// UPDATE :: Update the specified resource in storage
##################################################################################################################
	public function update(UpdateUserRequest $request, $id)
	{
		// if(!checkACL('manager')) {
		//   return view('errors.403');
		// }

		// Get the user from the database
		$user = User::findOrFail($id);
			$user->username = $request->input('username');
			$user->email = $request->input('email');
			$user->role_id = $request->input('role_id');
		
		// Save the data to the database
		$user->save();

		// Save entry to log file using built-in Monolog
		//Log::info(Auth::user()->username . " (" . Auth::user()->id . ") UPDATED user (" . $user->id . ")\r\n", [$user = json_decode($user, true)]);

		// Set flash data with success message
		Session::flash ('success', 'The user was successfully updated!');
		// Redirect to posts.show
		return redirect()->route('backend.users.index');
	}


##################################################################################################################
# ██████╗ ███████╗███████╗████████╗██████╗  ██████╗ ██╗   ██╗
# ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔══██╗██╔═══██╗╚██╗ ██╔╝
# ██║  ██║█████╗  ███████╗   ██║   ██████╔╝██║   ██║ ╚████╔╝ 
# ██║  ██║██╔══╝  ╚════██║   ██║   ██╔══██╗██║   ██║  ╚██╔╝  
# ██████╔╝███████╗███████║   ██║   ██║  ██║╚██████╔╝   ██║   
# ╚═════╝ ╚══════╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝    ╚═╝   
// Remove the specified resource from storage
// Used in the index page and trashAll action to soft delete multiple records
##################################################################################################################
	public function destroy($id)
	{
		// if(!checkACL('manager')) {
		//   return view('errors.403');
		// }

		$user = User::findOrFail($id);
		
		// Delete the user's profile image
		// We will not do this here in case the user wants to re-activate his account
		// if($user->profile->image) {
		// 	unlink(public_path('_profiles/' . $user->profile->image));
		// }

		// Delete the Profile
		$user->profile->delete();

		// Delete user from Users table
		$user->delete();
		
		// Save entry to log file using built-in Monolog
		//Log::info(Auth::user()->username . " (" . Auth::user()->id . ") DELETED category (" . $category->id . ")\r\n", [$category = json_decode($category, true)]);

		Session::flash('success', 'The user and his profile have successfully been trashed!');
		return redirect()->route('backend.users.index');
	}


##################################################################################################################
# ████████╗██████╗  █████╗ ███████╗██╗  ██╗███████╗██████╗ 
# ╚══██╔══╝██╔══██╗██╔══██╗██╔════╝██║  ██║██╔════╝██╔══██╗
#    ██║   ██████╔╝███████║███████╗███████║█████╗  ██║  ██║
#    ██║   ██╔══██╗██╔══██║╚════██║██╔══██║██╔══╝  ██║  ██║
#    ██║   ██║  ██║██║  ██║███████║██║  ██║███████╗██████╔╝
#    ╚═╝   ╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝╚══════╝╚═════╝ 
// Display a list of resources that have been trashed (Soft Deleted)
##################################################################################################################
   public function trashed(Request $request)
   {
      // if(!checkACL('guest')) {
      //     return view('errors.403');
      // }

      $users = User::onlyTrashed()->get();
      // dd($users);
      return view('backend.users.trashed', compact('users'));
   }


##################################################################################################################
# ██████╗ ███████╗███████╗████████╗ ██████╗ ██████╗ ███████╗
# ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
# ██████╔╝█████╗  ███████╗   ██║   ██║   ██║██████╔╝█████╗  
# ██╔══██╗██╔══╝  ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝  
# ██║  ██║███████╗███████║   ██║   ╚██████╔╝██║  ██║███████╗
# ╚═╝  ╚═╝╚══════╝╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
// RESTORE TRASHED FILE
##################################################################################################################
   public function restore($id)
   {
      $user = User::withTrashed()->findOrFail($id);

      // Restore the user's profile
      $user->profile()->withTrashed()->restore();
		
		// Restore the user's account
		$user->restore();

      Session::flash ('success','The user was successfully restored.');
      return redirect()->route('backend.users.trashed');
   }


##################################################################################################################
# ██████╗ ███████╗██╗     ███████╗████████╗███████╗    ████████╗██████╗  █████╗ ███████╗██╗  ██╗███████╗██████╗ 
# ██╔══██╗██╔════╝██║     ██╔════╝╚══██╔══╝██╔════╝    ╚══██╔══╝██╔══██╗██╔══██╗██╔════╝██║  ██║██╔════╝██╔══██╗
# ██║  ██║█████╗  ██║     █████╗     ██║   █████╗         ██║   ██████╔╝███████║███████╗███████║█████╗  ██║  ██║
# ██║  ██║██╔══╝  ██║     ██╔══╝     ██║   ██╔══╝         ██║   ██╔══██╗██╔══██║╚════██║██╔══██║██╔══╝  ██║  ██║
# ██████╔╝███████╗███████╗███████╗   ██║   ███████╗       ██║   ██║  ██║██║  ██║███████║██║  ██║███████╗██████╔╝
# ╚═════╝ ╚══════╝╚══════╝╚══════╝   ╚═╝   ╚══════╝       ╚═╝   ╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝╚══════╝╚═════╝ 
// Permanently remove the specified resource from storage - individual record
##################################################################################################################
   public static function deleteTrashed($id)
   {
      // if(!checkACL('manager')) {
         // return view('errors.403');
      // }
      //dd($id);
      $user = User::withTrashed()->findOrFail($id);
      $user->forceDelete();

      Session::flash ('success','The user was deleted successfully.');
      return redirect()->route('backend.users.trashed');
   }


##################################################################################################################
#  ██████╗██╗  ██╗ █████╗ ███╗   ██╗ ██████╗ ███████╗    ██████╗ ██╗    ██╗██████╗ 
# ██╔════╝██║  ██║██╔══██╗████╗  ██║██╔════╝ ██╔════╝    ██╔══██╗██║    ██║██╔══██╗
# ██║     ███████║███████║██╔██╗ ██║██║  ███╗█████╗      ██████╔╝██║ █╗ ██║██║  ██║
# ██║     ██╔══██║██╔══██║██║╚██╗██║██║   ██║██╔══╝      ██╔═══╝ ██║███╗██║██║  ██║
# ╚██████╗██║  ██║██║  ██║██║ ╚████║╚██████╔╝███████╗    ██║     ╚███╔███╔╝██████╔╝
#  ╚═════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝ ╚═════╝ ╚══════╝    ╚═╝      ╚══╝╚══╝ ╚═════╝ 
##################################################################################################################
	public function changePwd(Request $request, $id)
	{
		$user = User::findOrFail($id);
		//dd($user);

		return view('backend.users.changePwd', compact('user'));
	}


##################################################################################################################
#  ██████╗██╗  ██╗ █████╗ ███╗   ██╗ ██████╗ ███████╗    ██████╗ ██╗    ██╗██████╗ 
# ██╔════╝██║  ██║██╔══██╗████╗  ██║██╔════╝ ██╔════╝    ██╔══██╗██║    ██║██╔══██╗
# ██║     ███████║███████║██╔██╗ ██║██║  ███╗█████╗      ██████╔╝██║ █╗ ██║██║  ██║
# ██║     ██╔══██║██╔══██║██║╚██╗██║██║   ██║██╔══╝      ██╔═══╝ ██║███╗██║██║  ██║
# ╚██████╗██║  ██║██║  ██║██║ ╚████║╚██████╔╝███████╗    ██║     ╚███╔███╔╝██████╔╝
#  ╚═════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝ ╚═════╝ ╚══════╝    ╚═╝      ╚══╝╚══╝ ╚═════╝ 
##################################################################################################################
	public function changePassword(Request $request, $id){
	
		// if (!(Hash::check($request->get('current-password'), Auth::user()->password))) {
		// // The current password does not match the one provided
		// return redirect()->back()->with("error","Your current password does not match the password you provided. Please try again.")->withInput(['tab'=>'changePwd']);
		// }
		//dd($request);

		// if(strcmp($request->get('current-password'), $request->get('new-password')) == 0){
		// // Current password and new password are the same
		// return redirect()->back()->with("error","The new password cannot be the same as your current password. Please choose a different password.")->withInput(['tab'=>'changePwd']);
		// }

		$validatedData = $request->validate([
		//'current-password' => '<PASSWORD>',
		'new-password' => '<PASSWORD>|string|min:6|confirmed',
		]);

		//Change Password
		$user = User::findOrFail($id);
			$user->password = <PASSWORD>($request->get('new-password'));
		$user->save();
		
		Session::flash ('success', $user->username . '\'s password was reset successfully.');
      return redirect()->route('backend.users.index');

		// return redirect()->back()->with("success","Password changed successfully!")->withInput(['tab'=>'changePwd']);
	}


##################################################################################################################
# ███╗   ██╗███████╗██╗    ██╗    ██╗   ██╗███████╗███████╗██████╗ ███████╗
# ████╗  ██║██╔════╝██║    ██║    ██║   ██║██╔════╝██╔════╝██╔══██╗██╔════╝
# ██╔██╗ ██║█████╗  ██║ █╗ ██║    ██║   ██║███████╗█████╗  ██████╔╝███████╗
# ██║╚██╗██║██╔══╝  ██║███╗██║    ██║   ██║╚════██║██╔══╝  ██╔══██╗╚════██║
# ██║ ╚████║███████╗╚███╔███╔╝    ╚██████╔╝███████║███████╗██║  ██║███████║
# ╚═╝  ╚═══╝╚══════╝ ╚══╝╚══╝      ╚═════╝ ╚══════╝╚══════╝╚═╝  ╚═╝╚══════╝
// Display a listing of the resource that were created since the user's last login.
##################################################################################################################
   public function newUsers(Request $request, $key=null)
   {
      // if(!checkACL('guest')) {
      //     return view('errors.403');
      // }

      //$alphas = range('A', 'Z');
      $alphas = DB::table('users')
         ->select(DB::raw('DISTINCT LEFT(username, 1) as letter'))
         ->where('created_at', '>=' , Auth::user()->last_login_date)
         //->where('user_id', '=', Auth::user()->id)
         // ->where('personal', '!=', 1)
         // ->where('published_at','!=', null)
         ->orderBy('letter')
         ->get();
      //dd($alphas);

      $letters = [];
      foreach($alphas as $alpha) {
        $letters[] = $alpha->letter;
      }

      // If $key value is passed
      if ($key) {
         $users = User::with('role','profile')->newUsers()
            ->where('username', 'like', $key . '%')
            ->get();
         return view('backend.users.newUsers', compact('users','letters'));
      }

      $users = User::with('role','profile')->newUsers()->get();
      return view('backend.users.newUsers', compact('users','letters'));
   }


##################################################################################################################
# ██╗███╗   ██╗ █████╗  ██████╗████████╗██╗██╗   ██╗███████╗    ██╗   ██╗███████╗███████╗██████╗ ███████╗
# ██║████╗  ██║██╔══██╗██╔════╝╚══██╔══╝██║██║   ██║██╔════╝    ██║   ██║██╔════╝██╔════╝██╔══██╗██╔════╝
# ██║██╔██╗ ██║███████║██║        ██║   ██║██║   ██║█████╗      ██║   ██║███████╗█████╗  ██████╔╝███████╗
# ██║██║╚██╗██║██╔══██║██║        ██║   ██║╚██╗ ██╔╝██╔══╝      ██║   ██║╚════██║██╔══╝  ██╔══██╗╚════██║
# ██║██║ ╚████║██║  ██║╚██████╗   ██║   ██║ ╚████╔╝ ███████╗    ╚██████╔╝███████║███████╗██║  ██║███████║
# ╚═╝╚═╝  ╚═══╝╚═╝  ╚═╝ ╚═════╝   ╚═╝   ╚═╝  ╚═══╝  ╚══════╝     ╚═════╝ ╚══════╝╚══════╝╚═╝  ╚═╝╚══════╝
// Display a listing of the resource that were created since the user's last login.
##################################################################################################################
   public function inactiveUsers(Request $request, $key=null)
   {
      // if(!checkACL('guest')) {
      //     return view('errors.403');
      // }

      //$alphas = range('A', 'Z');
      $alphas = DB::table('users')
         ->select(DB::raw('DISTINCT LEFT(username, 1) as letter'))
         //->where('user_id', '=', Auth::user()->id)
         ->where('login_count', '=', 0)
         // ->where('published_at','!=', null)
         ->orderBy('letter')
         ->get();
      //dd($alphas);

      $letters = [];
      foreach($alphas as $alpha) {
        $letters[] = $alpha->letter;
      }

      // If $key value is passed
      if ($key) {
         $users = User::inactiveUsers()
            ->where('username', 'like', $key . '%')
            ->get();
         return view('backend.users.inactiveUsers', compact('users','letters'));
      }

      $users = User::inactiveUsers()->get();
      return view('backend.users.inactiveUsers', compact('users','letters'));
   }


}
<file_sep><?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class WoodProjectImage extends Model
{
   protected $table = 'image_woodproject';
   
   protected $fillable = ['project_id', 'description', 'image', 'title', 'size'];

   // An ImageProject belongs to a Project
   public function woodProject() {
      return $this->belongsTo('App\WoodProject');
   }
}<file_sep><?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use App\User;
use App\Profile;
use Carbon\Carbon;
use Auth;
use Session;

class LoginController extends Controller
{
	/*
	|--------------------------------------------------------------------------
	| Login Controller
	|--------------------------------------------------------------------------
	|
	| This controller handles authenticating users for the application and
	| redirecting them to your home screen. The controller uses a trait
	| to conveniently provide its functionality to your applications.
	|
	*/

	use AuthenticatesUsers;

	/**
	* Where to redirect users after login.
	*
	* @var string
	*/
	// No longer needed as we override the authenticated function below
	//protected $redirectTo = '/';

	/**
	* Create a new controller instance.
	*
	* @return void
	*/
	public function __construct()
	{
	  $this->middleware('guest')->except('logout');
	}

	/**
	* Get the needed authorization credentials from the request.
	*
	* @param  \Illuminate\Http\Request  $request
	* @return array
	*/
	protected function credentials(Request $request)
	{
		$field = filter_var($request->get($this->username()), FILTER_VALIDATE_EMAIL)
			? $this->username()
			: 'username';

		return [
			$field => $request->get($this->username()),
			'password' => $request->password,
		];
	}

	// Override the default function form Laravel
	protected function authenticated(Request $request, User $user)
	{
		// Check if user that is logging in has a profile
		if($user->profile) {
			// If a profile exists, redirect them to their homepage of choice
			return redirect()->intended(Auth::user()->profile->landingPage->name);
		}

		// User user that is loggin in does not have a profile
		// Create a profile for the user
		$user->profile()->save(new Profile);
		// Redirect the user to the homepage
		return redirect('/');

	}


	// protected function setUserSession($user)
	// {
	//     session(
	//         [
	//             'userName' => $user->username,
	//             'email' => $user->email,
	//             'emailPublic' => $user->email_public,
	//             'createdAt' => $user->created_at,
	//             'firstName' => $user->profile->first_name,
	//             'lastName' => $user->profile->last_name,
	//             'telephone' => $user->profile->telephone,
	//             'authorFormat' => $user->profile->author_format,
	//             'dateFormat' => $user->profile->date_format,
	//             'image' => $user->profile->image,
	//             'rowsPerPage' => $user->profile->rows_per_page,
	//         ]
	//     );
	// }

	/**
	* Log the user out of the application.
	*
	* @return \Illuminate\Http\Response
	*/
	public function logout(Request $request)
	{
		$user = Auth::user();
			$user->last_login_date = Carbon::Now();
		$user->save();

		$this->guard()->logout();

		$request->session()->invalidate();

		return redirect('/');
	}

}
<file_sep><?php

use Illuminate\Database\Seeder;
use Faker\Factory as Faker;
use App\Client;

class InvoicesTableSeeder extends Seeder
{
	/**
	 * Run the database seeds.
	 *
	 * @return void
	 */
	public function run()
	{
		$faker = Faker::create();

		// following line retrieve all the user_ids from DB
		$clients = Client::all()->pluck('id');

		foreach (range(1,25) as $index) {

			$amount_charged = $faker->numberBetween($min = 1000, $max = 9000);
			$hst = $amount_charged * 0.13;
			$sub_total = $amount_charged + $hst;
			$wsib = $amount_charged * 0.06;
			$income_taxes = $amount_charged * 0.26;
			$total_deductions = $wsib + $income_taxes;
			$total = $amount_charged - $wsib - $income_taxes;

			DB::table('invoices')->insert([
				'client_id' => $faker->randomElement($clients),
				// 'work_date' => $faker->dateTimeThisYear($max = 'now', $timezone = null),
				'notes' => $faker->paragraph,
				'status' => $faker->randomElement($array = array ('logged','invoiced','paid')),
				'amount_charged' => $amount_charged,
				'hst' => $hst,
				'sub_total' => $sub_total,
				'wsib' => $wsib,
				'income_taxes' => $income_taxes,
				'total_deductions' => $total_deductions,
				'total' => $total,
				'created_at' => $faker->dateTimeThisYear($max = 'now', $timezone = null),
				'updated_at' => $faker->dateTimeThisYear($max = 'now', $timezone = null)
			]);
		}
	}
}
<file_sep><?php

// ARTICLES
Route::group(['prefix'=>'articles'], function () {

   Route::get('newArticles/{key?}',       'ArticlesController@newArticles')      ->name('articles.newArticles');
   // Route::get('published/{key?}',         'ArticlesController@published')        ->name('articles.published');
   Route::get('unpublished/{key?}',       'ArticlesController@unpublished')      ->name('articles.unpublished');
   Route::get('future/{key?}',            'ArticlesController@future')           ->name('articles.future');
   Route::get('myArticles/{key?}',        'ArticlesController@myArticles')       ->name('articles.myArticles');
   Route::get('showTrashed/{id}',         'ArticlesController@showTrashed')      ->name('articles.showTrashed');

   Route::get('myFavorites',              'ArticlesController@myFavorites')      ->name('articles.myFavorites');
   Route::get('trashed',                  'ArticlesController@trashed')          ->name('articles.trashed');
   Route::get('create',                   'ArticlesController@create')           ->name('articles.create');

   Route::get('{id}/addFavorite',         'ArticlesController@addFavorite')      ->name('articles.addFavorite');
   Route::get('{id}/removeFavorite',      'ArticlesController@removeFavorite')   ->name('articles.removeFavorite');
   Route::get('{id}/duplicate',           'ArticlesController@duplicate')        ->name('articles.duplicate');
   Route::get('{id}/publish',             'ArticlesController@publish')          ->name('articles.publish');
   Route::get('{id}/unpublish',           'ArticlesController@unpublish')        ->name('articles.unpublish');
   Route::get('{id}/resetViews',          'ArticlesController@resetViews')       ->name('articles.resetViews');
   Route::get('{id}/edit',                'ArticlesController@edit')             ->name('articles.edit');
   Route::get('{id}/show',                'ArticlesController@show')             ->name('articles.show');
   Route::get('/{key?}',                  'ArticlesController@index')            ->name('articles.index');

   Route::get('print/{id}',               'ArticlesController@print')            ->name('articles.print');
   Route::get('import',                   'ArticlesController@import')           ->name('articles.import');
   Route::get('downloadExcel/{type}',     'ArticlesController@downloadExcel')    ->name('articles.downloadExcel');
   Route::get('restore/{id}',             'ArticlesController@restore')          ->name('articles.restore');
   Route::get('pdfview',                  'ArticlesController@pdfview')          ->name('articles.pdfview');
   Route::get('archives/{year}/{month}',  'ArticlesController@archive')          ->name('articles.archive');

   Route::put('update/{id}',              'ArticlesController@update')           ->name('articles.update');

   Route::post('',                        'ArticlesController@store')            ->name('articles.store');
   Route::post('{id}/storeComment',       'ArticlesController@storeComment')     ->name('articles.storeComment');
   Route::post('trashAll',                'ArticlesController@trashAll')         ->name('articles.trashAll');
   Route::post('deleteAll',               'ArticlesController@deleteAll')        ->name('articles.deleteAll');
   Route::post('restoreAll',              'ArticlesController@restoreAll')       ->name('articles.restoreAll');
   Route::post('importExcel',             'ArticlesController@importExcel')      ->name('articles.importExport');
   Route::post('unpublishAll',            'ArticlesController@unpublishAll')     ->name('articles.unpublishAll');
   Route::post('publishAll',              'ArticlesController@publishAll')       ->name('articles.publishAll');

   Route::delete('{id}',                  'ArticlesController@destroy')          ->name('articles.destroy');
   Route::delete('deleteTrashed/{id}',    'ArticlesController@deleteTrashed')    ->name('articles.deleteTrashed');
});
// Route::get('articles/{key?}',                  'ArticlesController@index')            ->name('articles.index');<file_sep><?php

// ROLES

Route::get('role/{id}',        ['uses' => 'RolesController@show',            'as' => 'roles.show']);

Route::group(['prefix'=>'roles'], function()
{
   $c = 'RolesController@';
   $r = 'roles.';

   Route::get('newRoles',                 ['uses' => $c . 'newRoles',            'as' => $r . 'newRoles']);

   Route::get('create',                   ['uses' => $c . 'create',              'as' => $r . 'create']);
   Route::post('store',                   ['uses' => $c . 'store',               'as' => $r . 'store']);
   Route::get('{key?}',                   ['uses' => $c . 'index',               'as' => $r . 'index']);
   Route::get('{id}/edit',                ['uses' => $c . 'edit',                'as' => $r . 'edit']);
   Route::put('{id}',                     ['uses' => $c . 'update',              'as' => $r . 'update']);
   Route::delete('{id}',                  ['uses' => $c . 'destroy',             'as' => $r . 'destroy']);
   Route::delete('deleteTrashed/{id}',    'RolesController@deleteTrashed')        ->name('roles.deleteTrashed');


});
<file_sep><?php

use Illuminate\Database\Seeder;

class ImageWoodprojectTableSeeder extends Seeder
{

    /**
     * Auto generated seed file
     *
     * @return void
     */
    public function run()
    {
        

        \DB::table('image_woodproject')->delete();
        
        \DB::table('image_woodproject')->insert(array (
            0 => 
            array (
                'id' => 18,
                'wood_project_id' => 12,
                'ori_name' => 'Chrysanthemum',
                'new_name' => 'Chrysanthemum_1517502104.jpg',
                'size' => '879394',
                'description' => NULL,
                'created_at' => '2018-02-01 11:21:44',
                'updated_at' => '2018-02-01 11:21:44',
            ),
            1 => 
            array (
                'id' => 19,
                'wood_project_id' => 12,
                'ori_name' => 'Hydrangeas',
                'new_name' => 'Hydrangeas_1517502118.jpg',
                'size' => '595284',
                'description' => NULL,
                'created_at' => '2018-02-01 11:21:58',
                'updated_at' => '2018-02-01 11:21:58',
            ),
        ));
        
        
    }
}<file_sep><?php

use Illuminate\Database\Seeder;

class ModulesTableSeeder extends Seeder
{

    /**
     * Auto generated seed file
     *
     * @return void
     */
    public function run()
    {
        

        \DB::table('modules')->delete();
        
        \DB::table('modules')->insert(array (
            0 => 
            array (
                'id' => 1,
                'name' => 'articles',
                'created_at' => NULL,
                'updated_at' => NULL,
            ),
            1 => 
            array (
                'id' => 2,
                'name' => 'posts',
                'created_at' => NULL,
                'updated_at' => NULL,
            ),
            2 => 
            array (
                'id' => 3,
                'name' => 'recipes',
                'created_at' => NULL,
                'updated_at' => NULL,
            ),
            3 => 
            array (
                'id' => 4,
                'name' => 'wood projects',
                'created_at' => NULL,
                'updated_at' => NULL,
            ),
            4 => 
            array (
                'id' => 5,
                'name' => 'wood specie',
                'created_at' => NULL,
                'updated_at' => NULL,
            ),
            5 => 
            array (
                'id' => 6,
                'name' => 'wood type',
                'created_at' => NULL,
                'updated_at' => NULL,
            ),
            6 => 
            array (
                'id' => 7,
                'name' => 'stain type',
                'created_at' => NULL,
                'updated_at' => NULL,
            ),
            7 => 
            array (
                'id' => 8,
                'name' => 'stain color',
                'created_at' => NULL,
                'updated_at' => NULL,
            ),
            8 => 
            array (
                'id' => 9,
                'name' => 'stain sheen',
                'created_at' => NULL,
                'updated_at' => NULL,
            ),
            9 => 
            array (
                'id' => 10,
                'name' => 'finish type',
                'created_at' => NULL,
                'updated_at' => NULL,
            ),
            10 => 
            array (
                'id' => 11,
                'name' => '<NAME>',
                'created_at' => NULL,
                'updated_at' => NULL,
            ),
            11 => 
            array (
                'id' => 14,
                'name' => '<NAME>',
                'created_at' => NULL,
                'updated_at' => NULL,
            ),
        ));
        
        
    }
}<file_sep><?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Auth;

class Album extends Model
{
	protected $fillable = ['name', 'description', 'cover_image'];

	// An album has many photos
	public function photos() {
		return $this->hasMany('App\Photo');
	}

   public function scopeNewAlbums($query)
   {
      return $query
         ->where('created_at', '>=' , Auth::user()->last_login_date)
         //->where('user_id', '=', Auth::user()->id)
         ->orderBy('name','DESC');
   }

}
<file_sep><?php

namespace App\Http\Controllers\Backend;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Category;
use App\WoodProject;
use Auth;
use DB;
use File;
use Image;
use Session;

class WoodProjectsController extends Controller
{

##################################################################################################################
#  ██████╗ ██████╗ ███╗   ██╗███████╗████████╗██████╗ ██╗   ██╗ ██████╗████████╗
# ██╔════╝██╔═══██╗████╗  ██║██╔════╝╚══██╔══╝██╔══██╗██║   ██║██╔════╝╚══██╔══╝
# ██║     ██║   ██║██╔██╗ ██║███████╗   ██║   ██████╔╝██║   ██║██║        ██║   
# ██║     ██║   ██║██║╚██╗██║╚════██║   ██║   ██╔══██╗██║   ██║██║        ██║   
# ╚██████╗╚██████╔╝██║ ╚████║███████║   ██║   ██║  ██║╚██████╔╝╚██████╗   ██║   
#  ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝  ╚═════╝   ╚═╝   
##################################################################################################################
	public function __construct() {
		// only allow authenticated users to access these pages
		//$this->middleware('auth', ['except'=>['index','show']]);
		// changing auth to guest would only allow guests to access these pages
		// you can also restrict the actions by adding ['except' => 'name_of_action'] at the end
		$this->middleware('auth');

		//Log::useFiles(storage_path().'/logs/articles.log');
		//Log::useFiles(storage_path().'/logs/audits.log');
	}


##################################################################################################################
#  █████╗ ██████╗ ███╗   ███╗██╗███╗   ██╗
# ██╔══██╗██╔══██╗████╗ ████║██║████╗  ██║
# ███████║██║  ██║██╔████╔██║██║██╔██╗ ██║
# ██╔══██║██║  ██║██║╚██╔╝██║██║██║╚██╗██║
# ██║  ██║██████╔╝██║ ╚═╝ ██║██║██║ ╚████║
# ╚═╝  ╚═╝╚═════╝ ╚═╝     ╚═╝╚═╝╚═╝  ╚═══╝
##################################################################################################################
	public function admin() {
		return view('backend.woodProjects.admin.index');
	}


##################################################################################################################
#  ██████╗██████╗ ███████╗ █████╗ ████████╗███████╗
# ██╔════╝██╔══██╗██╔════╝██╔══██╗╚══██╔══╝██╔════╝
# ██║     ██████╔╝█████╗  ███████║   ██║   █████╗  
# ██║     ██╔══██╗██╔══╝  ██╔══██║   ██║   ██╔══╝  
# ╚██████╗██║  ██║███████╗██║  ██║   ██║   ███████╗
#  ╚═════╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝   ╚═╝   ╚══════╝
// Show the form for creating a new resource
##################################################################################################################
	public function create()
	{
		// find all projects categories in the categories table and pass them to the view
		$categories = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'wood projects');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$cats = [];

		// Store the category values into the $cats array
		foreach ($categories as $category) {
			$cats[$category->id] = $category->name;
		}

		// find all stain colors categories in the categories table and pass them to the view
		$stainColors = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'stain color');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$staincolors = [];

		// Store the category values into the $cats array
		foreach ($stainColors as $stainColor) {
			$staincolors[$stainColor->id] = $stainColor->name;
		}

		// find all stain sheens categories in the categories table and pass them to the view
		$stainSheens = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'stain sheen');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$stainsheens = [];

		// Store the category values into the $cats array
		foreach ($stainSheens as $stainSheen) {
			$stainsheens[$stainSheen->id] = $stainSheen->name;
		}

		// find all stain types categories in the categories table and pass them to the view
		$stainTypes = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'stain type');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$staintypes = [];

		// Store the category values into the $cats array
		foreach ($stainTypes as $stainType) {
			$staintypes[$stainType->id] = $stainType->name;
		}

		// find all wood species categories in the categories table and pass them to the view
		$woodSpecies = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'wood specie');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$woodspecies = [];

		// Store the category values into the $cats array
		foreach ($woodSpecies as $woodSpecie) {
			$woodspecies[$woodSpecie->id] = $woodSpecie->name;
		}

		// find all wood types categories in the categories table and pass them to the view
		$woodTypes = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'wood type');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$woodtypes = [];

		// Store the category values into the $cats array
		foreach ($woodTypes as $woodType) {
			$woodtypes[$woodType->id] = $woodType->name;
		}

		// find all wood types categories in the categories table and pass them to the view
		$finishTypes = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'finish type');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$finishtypes = [];

		// Store the category values into the $cats array
		foreach ($finishTypes as $finishType) {
			$finishtypes[$finishType->id] = $finishType->name;
		}

		// find all stain sheens categories in the categories table and pass them to the view
		$finishSheens = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'finish sheen');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$finishsheens = [];

		// Store the category values into the $cats array
		foreach ($finishSheens as $finishSheen) {
			$finishsheens[$finishSheen->id] = $finishSheen->name;
		}

		return view('backend.woodProjects.create')
			->withCategories($cats)
			->withWoodSpecies($woodspecies)
			->withWoodTypes($woodtypes)
			->withStainTypes($staintypes)
			->withStainColors($staincolors)
			->withStainSheens($stainsheens)
			->withFinishTypes($finishtypes)
			->withFinishSheens($finishsheens)
		;
	}


##################################################################################################################
# ██████╗ ███████╗███████╗████████╗██████╗  ██████╗ ██╗   ██╗
# ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔══██╗██╔═══██╗╚██╗ ██╔╝
# ██║  ██║█████╗  ███████╗   ██║   ██████╔╝██║   ██║ ╚████╔╝ 
# ██║  ██║██╔══╝  ╚════██║   ██║   ██╔══██╗██║   ██║  ╚██╔╝  
# ██████╔╝███████╗███████║   ██║   ██║  ██║╚██████╔╝   ██║   
# ╚═════╝ ╚══════╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝    ╚═╝   
// Remove the specified resource from storage
// Used in the index page and trashAll action to soft delete multiple records
##################################################################################################################
	public function destroy($id) {
		
		$project = WoodProject::find($id);
		//dd($project);
		foreach($project->projectImages as $photo) {
			unlink(public_path('_woodProjects/images/' . $project->id . "/" . $photo->new_name));
			unlink(public_path('_woodProjects/images/thumbs/' . $project->id . "/" . $photo->new_name));
			//Delete the photos of this project from the database
			$photo->delete();
		}

		// Delete the project cover image and it's thumbnail
		unlink(public_path('_woodProjects/main_images/' . $project->main_image));
		unlink(public_path('_woodProjects/main_images/thumbs/' . $project->main_image));
		
		// Delete the IMAGES/THUMBS folder matching the project id
		File::deleteDirectory(public_path('_woodProjects/images/thumbs/' . $project->id));
		// Delete the IMAGES folder matching the project id
		File::deleteDirectory(public_path('_woodProjects/images/' . $project->id));

		//Delete the project from the database
		$project->delete();

		Session::flash('success','Project and associated images have been deleted.');
		return redirect()->route('backend.woodProjects.index');
	}


##################################################################################################################
# ███████╗██████╗ ██╗████████╗
# ██╔════╝██╔══██╗██║╚══██╔══╝
# █████╗  ██║  ██║██║   ██║   
# ██╔══╝  ██║  ██║██║   ██║   
# ███████╗██████╔╝██║   ██║   
# ╚══════╝╚═════╝ ╚═╝   ╚═╝   
// Show the form for editing the specified resource
##################################################################################################################
	public function edit($id)
	{
		$project = WoodProject::find($id);

		// find all projects categories in the categories table and pass them to the view
		$categories = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'wood projects');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$cats = [];

		// Store the category values into the $cats array
		foreach ($categories as $category) {
			$cats[$category->id] = $category->name;
		}

		// find all stain colors categories in the categories table and pass them to the view
		$stainColors = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'stain color');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$staincolors = [];

		// Store the category values into the $cats array
		foreach ($stainColors as $stainColor) {
			$staincolors[$stainColor->id] = $stainColor->name;
		}

		// find all stain sheens categories in the categories table and pass them to the view
		$stainSheens = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'stain sheen');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$stainsheens = [];

		// Store the category values into the $cats array
		foreach ($stainSheens as $stainSheen) {
			$stainsheens[$stainSheen->id] = $stainSheen->name;
		}

		// find all stain types categories in the categories table and pass them to the view
		$stainTypes = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'stain type');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$staintypes = [];

		// Store the category values into the $cats array
		foreach ($stainTypes as $stainType) {
			$staintypes[$stainType->id] = $stainType->name;
		}

		// find all wood species categories in the categories table and pass them to the view
		$woodSpecies = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'wood specie');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$woodspecies = [];

		// Store the category values into the $cats array
		foreach ($woodSpecies as $woodSpecie) {
			$woodspecies[$woodSpecie->id] = $woodSpecie->name;
		}

		// find all wood types categories in the categories table and pass them to the view
		$woodTypes = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'wood type');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$woodtypes = [];

		// Store the category values into the $cats array
		foreach ($woodTypes as $woodType) {
			$woodtypes[$woodType->id] = $woodType->name;
		}

		// find all wood types categories in the categories table and pass them to the view
		$finishTypes = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'finish type');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$finishtypes = [];

		// Store the category values into the $cats array
		foreach ($finishTypes as $finishType) {
			$finishtypes[$finishType->id] = $finishType->name;
		}

		// find all stain sheens categories in the categories table and pass them to the view
		$finishSheens = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'finish sheen');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$finishsheens = [];

		// Store the category values into the $cats array
		foreach ($finishSheens as $finishSheen) {
			$finishsheens[$finishSheen->id] = $finishSheen->name;
		}
		
		return view('backend.woodProjects.edit', compact('project'))
			->withCategories($cats)
			->withWoodSpecies($woodspecies)
			->withWoodTypes($woodtypes)
			->withStainTypes($staintypes)
			->withStainColors($staincolors)
			->withStainSheens($stainsheens)
			->withFinishTypes($finishtypes)
			->withFinishSheens($finishsheens)
		;
	}


##################################################################################################################
# ██╗███╗   ██╗██████╗ ███████╗██╗  ██╗
# ██║████╗  ██║██╔══██╗██╔════╝╚██╗██╔╝
# ██║██╔██╗ ██║██║  ██║█████╗   ╚███╔╝ 
# ██║██║╚██╗██║██║  ██║██╔══╝   ██╔██╗ 
# ██║██║ ╚████║██████╔╝███████╗██╔╝ ██╗
# ╚═╝╚═╝  ╚═══╝╚═════╝ ╚══════╝╚═╝  ╚═╝
// Display a list of resources
##################################################################################################################
	public function index()
	{
		//$projects = WoodProject::with('Images')->get();
		$projects = WoodProject::orderBy('name','asc')->get();
		return view('backend.woodProjects.index', compact('projects'));
	}


##################################################################################################################
# ███████╗██╗  ██╗ ██████╗ ██╗    ██╗
# ██╔════╝██║  ██║██╔═══██╗██║    ██║
# ███████╗███████║██║   ██║██║ █╗ ██║
# ╚════██║██╔══██║██║   ██║██║███╗██║
# ███████║██║  ██║╚██████╔╝╚███╔███╔╝
# ╚══════╝╚═╝  ╚═╝ ╚═════╝  ╚══╝╚══╝ 
// Display the specified resource
##################################################################################################################
	public function show($id) {
		// $project = WoodProject::with('ImageProject')->find($id);
		$project = WoodProject::find($id);
		// dd($project);
		return view('backend.woodProjects.show', compact('project'));
	}


##################################################################################################################
# ███████╗████████╗ ██████╗ ██████╗ ███████╗
# ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
# ███████╗   ██║   ██║   ██║██████╔╝█████╗  
# ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝  
# ███████║   ██║   ╚██████╔╝██║  ██║███████╗
# ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
// Store a newly created resource in storage
##################################################################################################################
	public function store(Request $request) {
		
		$this->validate($request, [
			'name' => 'required',
			'description' => 'required',
			'category_id' => 'required',
			'main_image' => 'required|image|max:1999'
		]);


		// Get the file object
		$file = $request->file('main_image');

		// Get file name with extension
		$filenameWithExt = $request->file('main_image')->getClientOriginalName();

		// Get just the filename
		$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);

		// Get the extension
		$extension = $request->file('main_image')->getClientOriginalExtension();

		// Create the new filename
		$filenameToStore = $filename . '_' . time() . '.' . $extension;
		//return $filenameToStore;
		
		// Check if Gallery/Images folders exists
		if (!file_exists('_woodProjects/main_images')) {
			mkdir('_woodProjects/main_images', 0777, true);
		}

		// move the file to the correct location
		$file->move('_woodProjects/main_images', $filenameToStore);
		
		// Check if Thumbs folder exists under Images
		if (!file_exists('_woodProjects/main_images/thumbs')) {
			mkdir('_woodProjects/main_images/thumbs', 0777, true);
		}

		// Create thumbnail
		$thumb = Image::make('_woodProjects/main_images/' . $filenameToStore)
			->resize(240,160)
			->save('_woodProjects/main_images/thumbs/' . $filenameToStore, 60);

		//Create album
		$project = new WoodProject;
			$project->category_id = $request->input('category_id');
			$project->name = $request->input('name');
			$project->description = $request->input('description');
			$project->main_image = $filenameToStore;
			$project->time_invested = $request->input('time_invested');
			$project->price = $request->input('price');
			$project->wood_specie_id = $request->input('wood_specie_id');
			$project->wood_type_id = $request->input('wood_type_id');
			$project->width = $request->input('width');
			$project->depth = $request->input('depth');
			$project->height = $request->input('height');
			$project->stain_type_id = $request->input('stain_type_id');
			$project->stain_color_id = $request->input('stain_color_id');
			$project->stain_sheen_id = $request->input('stain_sheen_id');
			$project->finish_type_id = $request->input('finish_type_id');
			$project->finish_sheen_id = $request->input('finish_sheen_id');
			$project->completed_at = $request->input('completed_at');
			$project->weight = $request->input('weight');
		$project->save();

		Session::flash('success','Project created.');
		return redirect()->route('backend.woodProjects.index');
	}


##################################################################################################################
# ██╗   ██╗██████╗ ██████╗  █████╗ ████████╗███████╗
# ██║   ██║██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██╔════╝
# ██║   ██║██████╔╝██║  ██║███████║   ██║   █████╗  
# ██║   ██║██╔═══╝ ██║  ██║██╔══██║   ██║   ██╔══╝  
# ╚██████╔╝██║     ██████╔╝██║  ██║   ██║   ███████╗
#  ╚═════╝ ╚═╝     ╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚══════╝
// UPDATE :: Update the specified resource in storage
##################################################################################################################
	public function update(Request $request, $id)
	{
		$this->validate($request, [
			'name' => 'required',
			'description' => 'required',
			'category_id' => 'required',
			'main_image' => 'sometimes|image|max:1999'
		]);

		// if(!checkACL('author')) {
		//     return view('errors.403');
		// }

		//dd($request->ref);

		if($request->file('main_image')) {
			$project = WoodProject::find($id);
			// Delete the project cover image and it's thumbnail
			unlink(public_path('_woodProjects/main_images/' . $project->main_image));
			unlink(public_path('_woodProjects/main_images/thumbs/' . $project->main_image));

			// Get the file object
			$file = $request->file('main_image');

			// Get file name with extension
			$filenameWithExt = $request->file('main_image')->getClientOriginalName();

			// Get just the filename
			$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);

			// Get the extension
			$extension = $request->file('main_image')->getClientOriginalExtension();

			// Create the new filename
			$filenameToStore = $filename . '_' . time() . '.' . $extension;
			//return $filenameToStore;
			
			// Check if Gallery/Images folders exists
			if (!file_exists('_woodProjects/main_images')) {
				mkdir('_woodProjects/main_images', 0777, true);
			}

			// move the file to the correct location
			$file->move('_woodProjects/main_images', $filenameToStore);
			
			// Check if Thumbs folder exists under Images
			if (!file_exists('_woodProjects/main_images/thumbs')) {
				mkdir('_woodProjects/main_images/thumbs', 0777, true);
			}

			// Create thumbnail
			$thumb = Image::make('_woodProjects/main_images/' . $filenameToStore)
				->resize(240,160)
				->save('_woodProjects/main_images/thumbs/' . $filenameToStore, 60);
		}

		$project = WoodProject::findOrFail($id);
			$project->category_id = $request->input('category_id');
			$project->name = $request->input('name');
			$project->description = $request->input('description');
			if ($request->file('main_image')) {
				$project->main_image = $filenameToStore;
			}
			$project->time_invested = $request->input('time_invested');
			$project->price = $request->input('price');
			$project->wood_specie_id = $request->input('wood_specie_id');
			$project->wood_type_id = $request->input('wood_type_id');
			$project->width = $request->input('width');
			$project->depth = $request->input('depth');
			$project->height = $request->input('height');
			$project->stain_type_id = $request->input('stain_type_id');
			$project->stain_color_id = $request->input('stain_color_id');
			$project->stain_sheen_id = $request->input('stain_sheen_id');
			$project->finish_type_id = $request->input('finish_type_id');
			$project->finish_sheen_id = $request->input('finish_sheen_id');
			$project->completed_at = $request->input('completed_at');
			$project->weight = $request->input('weight');
		$project->save();
		
		// Save entry to log file using built-in Monolog
		//Log::info(Auth::user()->username . " (" . Auth::user()->id . ") UPDATED article (" . $article->id . ")\r\n",
		//    [json_decode($article, true)]
		//);

		Session::flash('success','The project has been updated successfully.');
		//return redirect()->route($request->ref);
		return redirect()->route('backend.woodProjects.index');
	}


##################################################################################################################
# ███╗   ██╗███████╗██╗    ██╗    ██████╗ ██████╗  ██████╗      ██╗███████╗ ██████╗████████╗███████╗
# ████╗  ██║██╔════╝██║    ██║    ██╔══██╗██╔══██╗██╔═══██╗     ██║██╔════╝██╔════╝╚══██╔══╝██╔════╝
# ██╔██╗ ██║█████╗  ██║ █╗ ██║    ██████╔╝██████╔╝██║   ██║     ██║█████╗  ██║        ██║   ███████╗
# ██║╚██╗██║██╔══╝  ██║███╗██║    ██╔═══╝ ██╔══██╗██║   ██║██   ██║██╔══╝  ██║        ██║   ╚════██║
# ██║ ╚████║███████╗╚███╔███╔╝    ██║     ██║  ██║╚██████╔╝╚█████╔╝███████╗╚██████╗   ██║   ███████║
# ╚═╝  ╚═══╝╚══════╝ ╚══╝╚══╝     ╚═╝     ╚═╝  ╚═╝ ╚═════╝  ╚════╝ ╚══════╝ ╚═════╝   ╚═╝   ╚══════╝
// Display a listing of the resource that were created since the user's last login.
##################################################################################################################
   public function newWoodProjects(Request $request, $key=null)
   {
      // if(!checkACL('guest')) {
      //     return view('errors.403');
      // }

      //$alphas = range('A', 'Z');
      $alphas = DB::table('woodprojects')
         ->select(DB::raw('DISTINCT LEFT(name, 1) as letter'))
         ->where('created_at', '>=' , Auth::user()->last_login_date)
         //->where('user_id', '=', Auth::user()->id)
         // ->where('personal', '!=', 1)
         // ->where('published_at','!=', null)
         ->orderBy('letter')
         ->get();
      //dd($alphas);

      $letters = [];
      foreach($alphas as $alpha) {
        $letters[] = $alpha->letter;
      }

      // If $key value is passed
      if ($key) {
         $projects = WoodProject::with('category')->newWoodProjects()
            ->where('name', 'like', $key . '%')
            ->get();
         return view('backend.woodProjects.newWoodProjects', compact('projects','letters'));
      }

      $projects = WoodProject::with('category')->newWoodProjects()->get();
      return view('backend.woodProjects.newWoodProjects', compact('projects','letters'));
   }



}
<file_sep><?php

namespace App\Http\Controllers\Frontend;

//use Illuminate\Http\Request;
//use App\Http\Requests;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use App\Comment;
use App\Post;
use Session;
use Log;
use Auth;
//use Request;

use App\Http\Requests\CreateCommentRequest;
//use App\Http\Requests\UpdateCommentRequest;

class CommentsController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth', ['except' => 'store']);
        //Log::useFiles(storage_path().'/logs/comments.log');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    // public function store(CreateCommentRequest $request, $post_id)
    // {
    //     $post = Post::find($post_id);

    //     $comment = new Comment();
    //         $comment->name = $request->name;
    //         $comment->email = $request->email;
    //         $comment->comment = $request->comment;
    //     $post->comments()->save($comment);
    //     //$comment->save();

    //     // Save entry to log file using built-in Monolog
    //     // if (Auth::check()) {
    //     //     Log::info(Auth::user()->username . " (" . Auth::user()->id . ") commented on post (" . $post->id . ")\r\n", [json_decode($comment, true)]);
    //     // } else {
    //     //     Log::info(Request::ip() . " commented on post " . $post->id);
    //     // }

    //     Session::flash('success', 'Comment added seccesfully.');
    //     return redirect()->route('blog.single', [$post->slug]);
    // }


    // public function show($id)
    // {
    //     //dd($id);

    //     $comment = Comment::find($id);
    //     //dd($comment);
    //     $nid = $comment->post_id;
    //     //dd($nid);
    //     // return view('backend.comments.show')->withComment($comment);
    //     //return view('backend.posts.show', compact('nid'));
    //     return redirect()->route('backend.posts.show', [$nid]);
    // }

    // /**
    //  * Show the form for editing the specified resource.
    //  *
    //  * @param  int  $id
    //  * @return \Illuminate\Http\Response
    //  */
    // public function edit($id)
    // {
    //     $comment = Comment::find($id);
    //     return view('backend.comments.edit')->withComment($comment);
    // }

    // /**
    //  * Update the specified resource in storage.
    //  *
    //  * @param  \Illuminate\Http\Request  $request
    //  * @param  int  $id
    //  * @return \Illuminate\Http\Response
    //  */
    // public function update(UpdateCommentRequest $request, $id)
    // {
    //     $comment = Comment::find($id);
    //         $comment->comment = $request->comment;
    //     $comment->save();

    //     // Save entry to log file using built-in Monolog
    //     // Log::info(Auth::user()->username . " (" . Auth::user()->id . ") UPDATED comment (" . $comment->id . ")\r\n", 
    //     //     [json_decode($comment, true)]
    //     // );

    //     Session::flash('success', 'Comment updated');
    //     return redirect()->route('backend.posts.show', $comment->post->id);
    // }

    // public function delete($id)
    // {
    //     $comment = Comment::find($id);
    //     return view('backend.comments.delete')->withComment($comment);
    // }

    // /**
    //  * Remove the specified resource from storage.
    //  *
    //  * @param  int  $id
    //  * @return \Illuminate\Http\Response
    //  */
    // public function destroy($id)
    // {
    //     $comment = Comment::find($id);
    //     $post_id = $comment->post->id;
    //     $comment->delete();

    //     // Save entry to log file using built-in Monolog
    //     // Log::info(Auth::user()->username . " (" . Auth::user()->id . ") DELETED comment (" . $comment->id . ")\r\n", 
    //     //     [json_decode($comment, true)]
    //     // );

    //     Session::flash('success', 'Comment Deleted');
    //     return redirect()->route('backend.posts.show', $post_id);
    // }
}
<file_sep><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
// use Illuminate\Support\Facades\Input;
use App\Client;
use App\Invoice;
use App\InvoiceItem;
use App\Product;
use carbon\Carbon;
use Config;
use DB;
use PDF;
use Session;

class InvoicesController extends Controller
{

	public function index()
	{
		$invoices = Invoice::sortable()
			->orderBy('id','desc')
			->paginate(Config::get('settings.rowsPerPage'));
		return view('invoicer.invoices.index', compact('invoices'));
	}


	public function create()
	{
		$clients = Client::orderBy('company_name','asc')->pluck('company_name','id');
		$products = Product::all();
		return view('invoicer.invoices.create', compact('clients','products'));
	}


	public function store(Request $request)
	{
		// validate the data
		$this->validate($request, [
			'client_id' => 'required',
			// 'work_date' => 'required',
			'status' => 'required'
		]);

		// save the data in the database
		$invoice = new Invoice;
			// $invoice->work_date = $request->work_date;
			$invoice->client_id = $request->client_id;
			$invoice->notes = $request->notes;
			$invoice->status = $request->status;
		$invoice->save();

		// Add items to InvoiceItem table
		if($request->invoiceItem) {
			foreach($request->invoiceItem as $data)
			{
				$item = new InvoiceItem($data);
					$item->invoice_id = $invoice->id;
				$item->save();
			}
		}

		// set a flash message to be displayed on screen
		Session::flash('success','The invoice was successfully saved!');

		// redirect to another page
	   return redirect()->route('invoicer.invoices.index');
	}


	public function show($id)
	{
		$invoice = Invoice::with('invoiceItems')->find($id);
		//dd($invoice);
		return view('invoicer.invoices.show', compact('invoice'));
	}


	public function edit($id)
	{
		$invoice = Invoice::with('InvoiceItems')->find($id);
		// dd($invoice);
		$clients = Client::orderBy('company_name','asc')->pluck('company_name','id');
		//$invoiceitems = InvoiceItem::where('invoice_id', $invoice->id);
		//dd($invoiceitems);
		return view('invoicer.invoices.edit', compact('invoice','clients'));
	}


	public function update(Request $request, $id)
	{
		// validate the data
		$this->validate($request,
			[
				'client_id' => 'required',
				'status' => 'required',
			]);

		$invoice = Invoice::find($id);
			// $invoice->work_date = $request->work_date;
			$invoice->client_id = $request->client_id;
			$invoice->notes = $request->notes;
			$invoice->status = $request->status;
			$invoice->invoiced_at = $request->invoiced_at;
			$invoice->paid_at = $request->paid_at;

			// Perform required calculations
			$inv_amount_charged = DB::table('invoiceitems')->where('invoice_id', '=', $invoice->id)->sum('total');
			$inv_hst = $inv_amount_charged * Config::get('invoicer.hst_rate');
			$inv_sub_total = $inv_amount_charged + $inv_hst;
			$inv_wsib = $inv_amount_charged * Config::get('invoicer.wsib_rate');
			$inv_income_taxes = $inv_amount_charged * Config::get('invoicer.income_tax_rate');
			$inv_total_deductions = $inv_wsib + $inv_income_taxes;
			$inv_total = $inv_amount_charged - $inv_total_deductions;
			
			// Set the values to be updated
			$invoice->amount_charged = $inv_amount_charged;
			$invoice->hst = $inv_hst;
			$invoice->sub_total = $inv_sub_total;
			$invoice->wsib = $inv_wsib;
			$invoice->income_taxes = $inv_income_taxes;
			$invoice->total_deductions = $inv_total_deductions;
			$invoice->total = $inv_total;
		$invoice->save();

		// Set flash data with success message
		Session::flash ('success', 'This invoice was successfully updated!');

		// Redirect to posts.show
		return redirect()->route('invoicer.invoices.index');
	}


	public function destroy($id)
	{
		$invoice = Invoice::find($id);
		$invoice->delete();
		Session::flash('success','The invoice was deleted successfully.');
		return redirect()->route('invoicer.invoices.index');
	}


	public function paid()
	{
		$invoices = Invoice::sortable()->where('status','=','paid')
			->paginate(Config::get('settings.rowsPerPage'));
		return view('invoicer.invoices.index', compact('invoices'));
	}


	public function invoiced()
	{
		$invoices = Invoice::sortable()->where('status','=','invoiced')
			->paginate(Config::get('settings.rowsPerPage'));
		return view('invoicer.invoices.index', compact('invoices'));
	}


	public function logged()
	{
		$invoices = Invoice::sortable()->where('status','=','logged')
			->paginate(Config::get('settings.rowsPerPage'));
		return view('invoicer.invoices.index', compact('invoices'));
	}


	public function status_invoiced($id)
	{
		$invoice = Invoice::findOrFail($id);
			$invoice->status = 'invoiced';
			$invoice->invoiced_at = Carbon::now();
		$invoice->save();

		// Set flash data with success message
		Session::flash ('success', 'This invoice was successfully updated!');

		// Redirect to posts.show
		return redirect()->route('invoicer.invoices.index');
	}


	public function status_invoiced_all()
	{
		$invoices = Invoice::where('status', '=', 'logged')->get();
			
			foreach($invoices as $invoice) {
				$invoice->status = 'invoiced';
				$invoice->invoiced_at = Carbon::now();
				$invoice->save();
			}

		// Set flash data with success message
		Session::flash ('success', 'All logged invoices have successfully been marked as invoiced!');

		// Redirect to posts.show
		return redirect()->route('invoicer.invoices.index');
	}


	public function status_paid($id)
	{
		$invoice = Invoice::findOrFail($id);
			$invoice->status = 'paid';
			$invoice->paid_at = Carbon::now();
		$invoice->save();

		// Set flash data with success message
		Session::flash ('success', 'This invoice was successfully updated!');

		// Redirect to posts.show
		return redirect()->route('invoicer.invoices.index');
	}


	public function status_paid_all()
	{
		$invoices = Invoice::where('status', '=', 'invoiced')->get();
			
			foreach($invoices as $invoice) {
				$invoice->status = 'paid';
				$invoice->paid_at = Carbon::now();
				$invoice->save();
			}

		// Set flash data with success message
		Session::flash ('success', 'All invoiced invoices have successfully been marked as paid!');

		// Redirect to posts.show
		return redirect()->route('invoicer.invoices.index');
	}


	// public function invoice_to_pdf($id)
 //   {
 //   	$invoice = Invoice::with('client','invoiceitems')->find($id);
 //   	//dd($invoice);
 //    	$pdf = PDF::loadView('invoicer.invoices.invoice_to_pdf', compact('invoice'));
	// 	return $pdf->download('invoice_'.$id.'.pdf');
 //   }

}


	// public function show($id)
	// {
	// 	$invoice = Invoice::with('invoiceItems')->find($id);
	// 	//dd($invoice);
	// 	return view('invoicer.invoices.show', compact('invoice'));
	// }<file_sep><?php

namespace App\Http\Controllers\Frontend;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Storage;
use App\WoodProjectImage;
use Session;
use Image;
use File;

class WoodProjectImagesController extends Controller
{

##################################################################################################################
#  ██████╗ ██████╗ ███╗   ██╗███████╗████████╗██████╗ ██╗   ██╗ ██████╗████████╗
# ██╔════╝██╔═══██╗████╗  ██║██╔════╝╚══██╔══╝██╔══██╗██║   ██║██╔════╝╚══██╔══╝
# ██║     ██║   ██║██╔██╗ ██║███████╗   ██║   ██████╔╝██║   ██║██║        ██║   
# ██║     ██║   ██║██║╚██╗██║╚════██║   ██║   ██╔══██╗██║   ██║██║        ██║   
# ╚██████╗╚██████╔╝██║ ╚████║███████║   ██║   ██║  ██║╚██████╔╝╚██████╗   ██║   
#  ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝  ╚═════╝   ╚═╝   
##################################################################################################################
   public function __construct() {
      // only allow authenticated users to access these pages
      //$this->middleware('auth', ['except'=>['index','show']]);
      // changing auth to guest would only allow guests to access these pages
      // you can also restrict the actions by adding ['except' => 'name_of_action'] at the end
      $this->middleware('auth');

      //Log::useFiles(storage_path().'/logs/articles.log');
      //Log::useFiles(storage_path().'/logs/audits.log');
   }


##################################################################################################################
# ███████╗██╗  ██╗ ██████╗ ██╗    ██╗
# ██╔════╝██║  ██║██╔═══██╗██║    ██║
# ███████╗███████║██║   ██║██║ █╗ ██║
# ╚════██║██╔══██║██║   ██║██║███╗██║
# ███████║██║  ██║╚██████╔╝╚███╔███╔╝
# ╚══════╝╚═╝  ╚═╝ ╚═════╝  ╚══╝╚══╝ 
// Display the specified resource
##################################################################################################################
   // public function show($id) {
   //    $image = woodProjectImage::find($id);
   //    return view('frontend.woodProjectImage.show', compact('image'));
   // }


}
<file_sep><?php

use Illuminate\Database\Seeder;
use Faker\Factory as Faker;

class ProductsTableSeeder extends Seeder
{
   /**
    * Run the database seeds.
    *
    * @return void
    */
   public function run()
   {
      $faker = Faker::create();

      foreach (range(1,15) as $index) {
      
         DB::table('products')->insert([
            'code' => $faker->word,
            'details' => $faker->sentence,
         ]);
      }

   }
   
}<file_sep><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Role;
use Auth;
use DB;
use Session;

use App\Http\Requests\CreateRoleRequest;
use App\Http\Requests\UpdateRoleRequest;

class RolesController extends Controller
{

##################################################################################################################
# ██╗███╗   ██╗██████╗ ███████╗██╗  ██╗
# ██║████╗  ██║██╔══██╗██╔════╝╚██╗██╔╝
# ██║██╔██╗ ██║██║  ██║█████╗   ╚███╔╝ 
# ██║██║╚██╗██║██║  ██║██╔══╝   ██╔██╗ 
# ██║██║ ╚████║██████╔╝███████╗██╔╝ ██╗
# ╚═╝╚═╝  ╚═══╝╚═════╝ ╚══════╝╚═╝  ╚═╝
// Display a list of resources
##################################################################################################################
	public function index(Request $request, $key=null)
	{
		// if(!checkACL('guest')) {
		//     return view('errors.403');
		// }

		//$alphas = range('A', 'Z');
		$alphas = DB::table('roles')
			->select(DB::raw('DISTINCT LEFT(name, 1) as letter'))
			//->where('published_at','<', Carbon::Now())
			//->where('deleted_at','=', Null)
			->orderBy('letter')
			->get();

		$letters = [];
		foreach($alphas as $alpha) {
		  $letters[] = $alpha->letter;
		}

		// If $key value is passed
		if ($key) {
			$roles = Role::where('name', 'like', $key . '%')
				->orderBy('name', 'asc')
				->get();
			return view('roles.index', compact('roles','letters'));
		}

		// No $key value is passed
		$roles = Role::all();
		return view('roles.index', compact('roles','letters'));
	}


##################################################################################################################
#  ██████╗██████╗ ███████╗ █████╗ ████████╗███████╗
# ██╔════╝██╔══██╗██╔════╝██╔══██╗╚══██╔══╝██╔════╝
# ██║     ██████╔╝█████╗  ███████║   ██║   █████╗  
# ██║     ██╔══██╗██╔══╝  ██╔══██║   ██║   ██╔══╝  
# ╚██████╗██║  ██║███████╗██║  ██║   ██║   ███████╗
#  ╚═════╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝   ╚═╝   ╚══════╝
// Show the form for creating a new resource
##################################################################################################################
	public function create()
	{
		return view('roles.create');
	}


##################################################################################################################
# ███████╗████████╗ ██████╗ ██████╗ ███████╗
# ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
# ███████╗   ██║   ██║   ██║██████╔╝█████╗  
# ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝  
# ███████║   ██║   ╚██████╔╝██║  ██║███████╗
# ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
// Store a newly created resource in storage
##################################################################################################################
	public function store(CreateRoleRequest $request)
	{
		$role = new Role;
			$role->id 				= $request->id;
			$role->name				= $request->name;
			$role->display_name	= $request->display_name;
			$role->description	= $request->description;
		$role->save();

		Session::flash('success','Role created successfully!');
		return redirect()->route('roles.index');
	}


##################################################################################################################
# ███████╗██╗  ██╗ ██████╗ ██╗    ██╗
# ██╔════╝██║  ██║██╔═══██╗██║    ██║
# ███████╗███████║██║   ██║██║ █╗ ██║
# ╚════██║██╔══██║██║   ██║██║███╗██║
# ███████║██║  ██║╚██████╔╝╚███╔███╔╝
# ╚══════╝╚═╝  ╚═╝ ╚═════╝  ╚══╝╚══╝ 
// Display the specified resource
##################################################################################################################
	public function show($id)
	{
		$role = Role::findOrFail($id);

		return view('roles.show', compact('role'));
	}


##################################################################################################################
# ███████╗██████╗ ██╗████████╗
# ██╔════╝██╔══██╗██║╚══██╔══╝
# █████╗  ██║  ██║██║   ██║   
# ██╔══╝  ██║  ██║██║   ██║   
# ███████╗██████╔╝██║   ██║   
# ╚══════╝╚═════╝ ╚═╝   ╚═╝   
// Show the form for editing the specified resource
##################################################################################################################
	public function edit($id)
	{
		$role = Role::findOrFail($id);
		return view('roles.edit', compact('role'));
	}


##################################################################################################################
# ██╗   ██╗██████╗ ██████╗  █████╗ ████████╗███████╗
# ██║   ██║██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██╔════╝
# ██║   ██║██████╔╝██║  ██║███████║   ██║   █████╗  
# ██║   ██║██╔═══╝ ██║  ██║██╔══██║   ██║   ██╔══╝  
# ╚██████╔╝██║     ██████╔╝██║  ██║   ██║   ███████╗
#  ╚═════╝ ╚═╝     ╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚══════╝
// UPDATE :: Update the specified resource in storage
##################################################################################################################
	public function update(UpdateRoleRequest $request, $id)
	{
		// if(!checkACL('manager')) {
		//   return view('errors.403');
		// }

		// Get the user from the database
		$role = Role::findOrFail($id);
			$role->id = $request->input('id');
			$role->name = $request->input('name');
			$role->display_name = $request->input('display_name');
			$role->description = $request->input('description');
		
		// Save the data to the database
		$role->save();

		// Save entry to log file using built-in Monolog
		//Log::info(Auth::user()->username . " (" . Auth::user()->id . ") UPDATED user (" . $user->id . ")\r\n", [$user = json_decode($user, true)]);

		// Set flash data with success message
		Session::flash ('success', 'The role was successfully updated!');
		// Redirect to posts.show
		return redirect()->route('roles.index');
  }


##################################################################################################################
# ██████╗ ███████╗███████╗████████╗██████╗  ██████╗ ██╗   ██╗
# ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔══██╗██╔═══██╗╚██╗ ██╔╝
# ██║  ██║█████╗  ███████╗   ██║   ██████╔╝██║   ██║ ╚████╔╝ 
# ██║  ██║██╔══╝  ╚════██║   ██║   ██╔══██╗██║   ██║  ╚██╔╝  
# ██████╔╝███████╗███████║   ██║   ██║  ██║╚██████╔╝   ██║   
# ╚═════╝ ╚══════╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝    ╚═╝   
// Remove the specified resource from storage
// Used in the index page and trashAll action to soft delete multiple records
##################################################################################################################
	public function destroy($id)
	{
		// if(!checkACL('manager')) {
		//   return view('errors.403');
		// }

		$role = Role::findOrFail($id);
		
		// Delete role from Roles table
		$role->delete();
		
		// Save entry to log file using built-in Monolog
		//Log::info(Auth::user()->username . " (" . Auth::user()->id . ") DELETED category (" . $category->id . ")\r\n", [$category = json_decode($category, true)]);

		Session::flash('success', 'The role has successfully been deleted!');
		return redirect()->route('roles.index');
	}


##################################################################################################################
# ███╗   ██╗███████╗██╗    ██╗    ██████╗  ██████╗ ██╗     ███████╗███████╗
# ████╗  ██║██╔════╝██║    ██║    ██╔══██╗██╔═══██╗██║     ██╔════╝██╔════╝
# ██╔██╗ ██║█████╗  ██║ █╗ ██║    ██████╔╝██║   ██║██║     █████╗  ███████╗
# ██║╚██╗██║██╔══╝  ██║███╗██║    ██╔══██╗██║   ██║██║     ██╔══╝  ╚════██║
# ██║ ╚████║███████╗╚███╔███╔╝    ██║  ██║╚██████╔╝███████╗███████╗███████║
# ╚═╝  ╚═══╝╚══════╝ ╚══╝╚══╝     ╚═╝  ╚═╝ ╚═════╝ ╚══════╝╚══════╝╚══════╝
// Display a listing of the resource that were created since the user's last login.
##################################################################################################################
   public function newRoles(Request $request, $key=null)
   {
      // if(!checkACL('guest')) {
      //     return view('errors.403');
      // }

      //$alphas = range('A', 'Z');
      $alphas = DB::table('roles')
         ->select(DB::raw('DISTINCT LEFT(name, 1) as letter'))
         ->where('created_at', '>=' , Auth::user()->last_login_date)
         //->where('user_id', '=', Auth::user()->id)
         // ->where('personal', '!=', 1)
         // ->where('published_at','!=', null)
         ->orderBy('letter')
         ->get();
      //dd($alphas);

      $letters = [];
      foreach($alphas as $alpha) {
        $letters[] = $alpha->letter;
      }

      // If $key value is passed
      if ($key) {
         $roles = Role::newRoles()
            ->where('name', 'like', $key . '%')
            ->get();
         return view('roles.newRoles', compact('roles','letters'));
      }

      $roles = Role::newRoles()->get();
      return view('roles.newRoles', compact('roles','letters'));
   }	
}
<file_sep><?php

use Illuminate\Database\Seeder;


class RolesTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('roles')->insert([
            'id' => 10,
            'name' => 'superadmin',
            'display_name' => 'Super Administrator',
            'description' => 'All privileges',
        ]);

        DB::table('roles')->insert([
            'id' => 20,
            'name' => 'admin',
            'display_name' => 'Administrator',
            'description' => 'Administrator of the site',
        ]);

        DB::table('roles')->insert([
            'id' => 30,
            'name' => 'manager',
            'display_name' => 'Manager',
            'description' => 'Profile, View, Create, Edit, Publish, Import/Export, Delete',
        ]);

        DB::table('roles')->insert([
            'id' => 40,
            'name' => 'publisher',
            'display_name' => 'Publisher',
            'description' => 'Profile, View, Create, Edit, Publish, Import/Export',
        ]);

        DB::table('roles')->insert([
            'id' => 50,
            'name' => 'editor',
            'display_name' => 'Editor',
            'description' => 'Profile, View, Create, Edit',
        ]);

        DB::table('roles')->insert([
            'id' => 55,
            'name' => 'timeTracker',
            'display_name' => 'Special - Luc',
            'description' => 'Special',
        ]);

        DB::table('roles')->insert([
            'id' => 60,
            'name' => 'author',
            'display_name' => 'Author',
            'description' => 'Profile, View, Create',
        ]);

        DB::table('roles')->insert([
            'id' => 70,
            'name' => 'user',
            'display_name' => 'User',
            'description' => 'Profile, View',
        ]);

        DB::table('roles')->insert([
            'id' => 80,
            'name' => 'guest',
            'display_name' => 'Authenticated User',
            'description' => 'Guest -> View only',
        ]);
    }
}
<file_sep><?php

namespace App\Http\Controllers\Darts;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
use Session;
use App\User;
use App\Dart;
use App\DartScore;


class GamesController extends Controller
{

   public function index()
   {
         return view('darts.index');
   }


   public function create()
   {
         $users = User::with('profile')->where('id', '!=', 1)->orderby('username','asc')->get();
         return view('darts.games.create', compact('users'));
   }


   public function store(Request $request)
   {
      // validate the data
      $this->validate($request, [
         'type' => 'required',
      ]);

      $game = new Dart;
         $game->type = $request->type;
         $game->status = 'New';
      $game->save();

      Session::flash('success','The game has been created.');
      return redirect()->route('darts.games.selectTeamsOrPlayers', $game->id);
   }


   public function selectTeamsOrPlayers($game_id)
   {
      $game = Dart::find($game_id);
      return view('darts.games.selectTeamsOrPlayers', compact('game'));
   }


   public function storeTeamsOrPlayers(Request $request)
   {
      $game = Dart::find($request->game_id);
         if($request->t_players) {
            $game->t1_players = $request->t_players;
            $game->t2_players = $request->t_players;
            $game->ind_players = null; 
         }
         if($request->ind_players){
            $game->t1_players = null;
            $game->t2_players = null;
            $game->ind_players = $request->ind_players; 
         }
      $game->save();

      Session::flash('success','The game has been created.');
      if($request->t_players) {
         return redirect()->route('darts.games.selectTeamPlayers', $game->id);
      } else {
         return redirect()->route('darts.games.selectPlayers', $game->id);
      }
   }


   // Select players when team play is selected
   public function selectTeamPlayers($game_id)
   {
      $game = Dart::find($game_id);
      $players = User::with('profile')->where('id', '!=', 1)->orderby('username', 'asc')->get();
      return view('darts.games.selectTeamPlayers', compact('players','game'));
   }


   // Save players when team play is selected
   public function storeTeamPlayers(Request $request)
   {
      $game = Dart::find($request->game_id);

      if (isset($request->team1players))
      {
         $shotOrder = 1;
         foreach($request->team1players as $player)
         {
            DB::insert('insert into dartgame_user (dartgame_id, team_id, user_id, shooting_order) values (?, ?, ?, ?)', [$game->id, 1, $player, $shotOrder]);
            $shotOrder = $shotOrder + 2;
         }
      }

      if (isset($request->team2players))
      {
         $shotOrder = 2;
         foreach($request->team2players as $player)
         {
            DB::insert('insert into dartgame_user (dartgame_id, team_id, user_id, shooting_order) values (?, ?, ?, ?)', [$game->id, 2, $player, $shotOrder]);
            $shotOrder = $shotOrder + 2;
         }

      }

      Session::flash('success','The game has been created.');
      return redirect()->route('darts.games.board');
   }


   // Select individual players when no team play is selected
   public function selectPlayers($game_id)
   {
      $game = Dart::find($game_id);
      $players = User::with('profile')->where('id', '!=', 1)->orderby('username', 'asc')->get();
      return view('darts.games.selectPlayers', compact('players','game'));
   }


   // Save individual players when no team play is selected
   public function storePlayers(Request $request)
   {

      $game = Dart::find($request->game_id);
      $shotOrder = 1;
      foreach($request->players as $player)
      {
         DB::insert('insert into dartgame_user (dartgame_id, user_id, shooting_order) values (?, ?, ?)', [$request->game_id, $player, $shotOrder]);
         $shotOrder = $shotOrder + 1;
      }
      
      Session::flash('success','The game has been created.');
      return redirect()->route('darts.games.board');
   }


   public function destroy($id)
   {
      // if(!checkACL('manager')) {
      //   return view('errors.403');
      // }

      $game = Dart::find($id);
      $game->delete();

      // Save entry to log file using built-in Monolog
      //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") DELETED category (" . $category->id . ")\r\n", [$category = json_decode($category, true)]);

      Session::flash('success', 'The game and related entries were successfully deleted!');
      return redirect()->route('darts.games.board');
   }


   public function board()
   {
      $games = Dart::orderby('id','desc')->get();
      return view('darts.games.board', compact('games'));
   }


   
}<file_sep><?php

namespace App\Http\Controllers\Backend;

//use Illuminate\Http\Request;
//use App\Http\Requests;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use App\Comment;
use App\Post;
use DB;
use Session;
use Log;
use Auth;
//use Request;

use App\Http\Requests\CreateCommentRequest;
use App\Http\Requests\UpdateCommentRequest;

class CommentsController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth', ['except' => 'store']);
        //Log::useFiles(storage_path().'/logs/comments.log');
    }

##################################################################################################################
# ██╗███╗   ██╗██████╗ ███████╗██╗  ██╗
# ██║████╗  ██║██╔══██╗██╔════╝╚██╗██╔╝
# ██║██╔██╗ ██║██║  ██║█████╗   ╚███╔╝ 
# ██║██║╚██╗██║██║  ██║██╔══╝   ██╔██╗ 
# ██║██║ ╚████║██████╔╝███████╗██╔╝ ██╗
# ╚═╝╚═╝  ╚═══╝╚═════╝ ╚══════╝╚═╝  ╚═╝
// Display a list of resources
##################################################################################################################
  public function index()
  {
   // if(!checkACL('manager')) {
   //   // Save entry to log file of failure
   //   Log::warning(Auth::user()->username . " (" . Auth::user()->id . ") tried to access the index page");
   //   return view('errors.403');
   // }

   // $categories = Category::orderBy('name')->get();
   $comments = Comment::all();

   // Save entry to log file using built-in Monolog
   //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") accessed :: Admin / Categories / Index");

   return view ('backend.comments.index', compact('comments'));
  }


    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(CreateCommentRequest $request, $post_id)
    {
        $post = Post::find($post_id);

        $comment = new Comment();
            $comment->name = $request->name;
            $comment->email = $request->email;
            $comment->comment = $request->comment;
            $comment->approved = true;
            $comment->post()->associate($post);
        $comment->save();

        // Save entry to log file using built-in Monolog
        // if (Auth::check()) {
        //     Log::info(Auth::user()->username . " (" . Auth::user()->id . ") commented on post (" . $post->id . ")\r\n", [json_decode($comment, true)]);
        // } else {
        //     Log::info(Request::ip() . " commented on post " . $post->id);
        // }

        Session::flash('success', 'Comment was added');
        return redirect()->route('frontend.blog.single', [$post->slug]);
    }


    public function show($id)
    {
        //dd($id);

        $comment = Comment::find($id);
        //dd($comment);
        //$nid = $comment->post_id;
        //dd($nid);
        return view('backend.comments.show')->withComment($comment);
        //return view('backend.comments.show', compact('comment'));
        // return redirect()->route('backend.comments.show', compact('comment'));
        // return redirect()->route('backend.comments.index');
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $comment = Comment::find($id);
        return view('backend.comments.edit')->withComment($comment);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(UpdateCommentRequest $request, $id)
    {
        $comment = Comment::find($id);
            $comment->name = $request->name;
            $comment->email = $request->email;
            $comment->comment = $request->comment;
        $comment->save();

        // Save entry to log file using built-in Monolog
        // Log::info(Auth::user()->username . " (" . Auth::user()->id . ") UPDATED comment (" . $comment->id . ")\r\n", 
        //     [json_decode($comment, true)]
        // );

        Session::flash('success', 'Comment updated successfully.');
        return redirect()->route('backend.comments.index');
    }

    public function delete($id)
    {
        $comment = Comment::find($id);
        return view('backend.comments.delete')->withComment($comment);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $comment = Comment::find($id);
        //$post_id = $comment->post->id;
        $comment->delete();

        // Save entry to log file using built-in Monolog
        // Log::info(Auth::user()->username . " (" . Auth::user()->id . ") DELETED comment (" . $comment->id . ")\r\n", 
        //     [json_decode($comment, true)]
        // );

        Session::flash('success', 'Comment Deleted');
        return redirect()->route('backend.comments.index');
    }


##################################################################################################################
# ███╗   ██╗███████╗██╗    ██╗     ██████╗ ██████╗ ███╗   ███╗███╗   ███╗███████╗███╗   ██╗████████╗███████╗
# ████╗  ██║██╔════╝██║    ██║    ██╔════╝██╔═══██╗████╗ ████║████╗ ████║██╔════╝████╗  ██║╚══██╔══╝██╔════╝
# ██╔██╗ ██║█████╗  ██║ █╗ ██║    ██║     ██║   ██║██╔████╔██║██╔████╔██║█████╗  ██╔██╗ ██║   ██║   ███████╗
# ██║╚██╗██║██╔══╝  ██║███╗██║    ██║     ██║   ██║██║╚██╔╝██║██║╚██╔╝██║██╔══╝  ██║╚██╗██║   ██║   ╚════██║
# ██║ ╚████║███████╗╚███╔███╔╝    ╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ╚═╝ ██║███████╗██║ ╚████║   ██║   ███████║
# ═╝  ╚═══╝╚══════╝ ╚══╝╚══╝      ╚═════╝ ╚═════╝ ╚═╝     ╚═╝╚═╝     ╚═╝╚══════╝╚═╝  ╚═══╝   ╚═╝   ╚══════╝
// Display a listing of the resource that were created since the user's last login.
##################################################################################################################
   public function newComments(Request $request, $key=null)
   {
      // if(!checkACL('guest')) {
      //     return view('errors.403');
      // }

      //$alphas = range('A', 'Z');
      // $alphas = DB::table('comments')
      //    ->select(DB::raw('DISTINCT LEFT(name, 1) as letter'))
      //    ->where('created_at', '>=' , Auth::user()->last_login_date)
      //    //->where('user_id', '=', Auth::user()->id)
      //    // ->where('personal', '!=', 1)
      //    // ->where('published_at','!=', null)
      //    ->orderBy('letter')
      //    ->get();
      // //dd($alphas);

      // $letters = [];
      // foreach($alphas as $alpha) {
      //   $letters[] = $alpha->letter;
      // }

      // If $key value is passed
      // if ($key) {
      //    $comments = Comment::newComments()
      //       ->where('name', 'like', $key . '%')
      //       ->get();
      //    return view('backend.comments.newComments', compact('comments','letters'));
      // }


   // if(!checkACL('manager')) {
   //   // Save entry to log file of failure
   //   Log::warning(Auth::user()->username . " (" . Auth::user()->id . ") tried to access the index page");
   //   return view('errors.403');
   // }

   // $categories = Category::orderBy('name')->get();
   $comments = Comment::where('created_at', '>=' , Auth::user()->last_login_date)->get();

   // Save entry to log file using built-in Monolog
   //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") accessed :: Admin / Categories / Index");

  //  return view ('backend.comments.index', compact('comments'));
  // }
      //$comments = Comment::newComments()->get();
      return view('backend.comments.newComments', compact('comments'));
   }
}
<file_sep><?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class DartScore extends Model
{
   protected $table = "dartscores";

   protected $fillable = [
      'user_id',
      'team_id',
      'game_id',
      'score',
      'remaining'
    ];

   public function user()
   {
      return $this->belongsTo('App\User');
   }

   public function team1players()
   {
      return $this->hasMany('App\User');
   }

   public function team2players()
   {
      return $this->hasMany('App\User');
   }
}
<file_sep><?php

Route::get('darts', 'DartsController@index')->name('darts.index');

Route::get('darts/games/board', 'DartsController@board')->name('darts.games.board');

Route::get('darts/games/selectTeamsOrPlayers/{gameID}',	'DartsController@selectTeamsOrPlayers')->name('darts.games.selectTeamsOrPlayers');
Route::post('darts/games/storeTeamsOrPlayers',				'DartsController@storeTeamsOrPlayers')->name('darts.games.storeTeamsOrPlayers');

Route::get('darts/games/selectTeamPlayers/{game_ID}',		'DartsController@selectTeamPlayers')		->name('darts.games.selectTeamPlayers');
Route::post('darts/games/storeTeamPlayers',					'DartsController@storeTeamPlayers')			->name('darts.games.storeTeamPlayers');

Route::get('darts/games/selectPlayers/{game_ID}',			'DartsController@selectPlayers')				->name('darts.games.selectPlayers');
Route::post('darts/games/storePlayers',						'DartsController@storePlayers')				->name('darts.games.storePlayers');

Route::get('darts/games/create/',		'Darts\GamesController@create')		->name('darts.game.create');
Route::post('darts/games/',				'Darts\GamesController@store')		->name('darts.games.store');
Route::get('darts/games/{id}/show',		'Darts\GamesController@show')			->name('darts.games.show');
Route::get('darts/games/{key?}',			'Darts\GamesController@index')		->name('darts.games.index');
Route::get('darts/games/{id}/edit',		'Darts\GamesController@edit')			->name('darts.games.edit');
Route::put('darts/games/{id}',			'Darts\GamesController@update')		->name('darts.games.update');
Route::delete('darts/games/{id}',		'Darts\GamesController@destroy')		->name('darts.games.destroy');

Route::get('darts/01/scores/teams/{id}',			'Darts\ZeroOne\Teams\ScoresController@index')		->name('darts.01.scores.teams.index');
Route::post('darts/01/scores/teams/store',		'Darts\ZeroOne\Teams\ScoresController@store')		->name('darts.01.scores.teams.store');

Route::get('darts/01/scores/players/{id}',		'Darts\ZeroOne\Players\ScoresController@index')		->name('darts.01.scores.players.index');
Route::post('darts/01/scores/players/store', 	'Darts\ZeroOne\Players\ScoresController@store')		->name('darts.01.scores.players.store');


Route::get('darts/cricket/scores/teams/{id}',		'Darts\Cricket\Teams\ScoresController@cricketTeamIndex')		->name('darts.cricket.scores.teams.index');
Route::get('darts/cricket/scores/players/{id}', 	'Darts\Cricket\Players\ScoresController@etPlayerIndex')		->name('darts.cricket.scores.players.index');

<file_sep><?php

// RECIPES
// Route::get('recipe/{id}',		['uses'=>'RecipesController@show',				'as'=>'recipes.show']);

Route::group(['prefix' => 'recipes'], function()
{

	Route::get('unpublished/{key?}',			'RecipesController@unpublished')				->name('recipes.unpublished');
	//Route::get('published/{key?}',			'RecipesController@published')				->name('recipes.published');
	Route::get('future/{key?}',				'RecipesController@future')					->name('recipes.future');
	Route::get('myRecipes/{key?}',			'RecipesController@myRecipes')				->name('recipes.myRecipes');
	Route::get('myFavorites',					'RecipesController@myFavorites')				->name('recipes.myFavorites');
	Route::get('newRecipes/{key?}',			'RecipesController@newRecipes')				->name('recipes.newRecipes');
	Route::get('trashed/{key?}',				'RecipesController@trashed')					->name('recipes.trashed');
	

	Route::get('import',							'RecipesController@import')					->name('recipes.import');
	Route::get('pdfview',						'RecipesController@pdfview')					->name('recipes.pdfview');

	Route::get('create',							'RecipesController@create')					->name('recipes.create');
	Route::post('store',							'RecipesController@store')						->name('recipes.store');
	Route::get('{id}/show',						'RecipesController@show')						->name('recipes.show');
	Route::get('{id?}',							'RecipesController@index')						->name('recipes.index');
	Route::get('{id}/edit',						'RecipesController@edit')						->name('recipes.edit');
	Route::put('{id}',							'RecipesController@update')					->name('recipes.update');
	Route::delete('{id}',						'RecipesController@destroy')					->name('recipes.destroy');

	Route::get('{id}/print',					'RecipesController@print')						->name('recipes.print');
	Route::get('{id}/publish',					'RecipesController@publish')					->name('recipes.publish');
	Route::get('{id}/resetViews',				'RecipesController@resetViews')				->name('recipes.resetViews');
	Route::post('publishAll',					'RecipesController@publishAll')				->name('recipes.publishAll');
	Route::get('{id}/unpublish', 				'RecipesController@unpublish')				->name('recipes.unpublish');
	Route::post('unpublishAll',				'RecipesController@unpublishAll')			->name('recipes.unpublishAll');

	Route::post('importExcel',					'RecipesController@importExcel')				->name('recipes.importExport');
	Route::get('downloadExcel/{type}',		'RecipesController@downloadExcel')			->name('recipes.downloadExcel');

	Route::get('restore/{id}',					'RecipesController@restore')					->name('recipes.restore');
	Route::post('restoreAll',					'RecipesController@restoreAll')				->name('recipes.restoreAll');
	Route::get('showTrashed/{id}',			'RecipesController@showTrashed')				->name('recipes.showTrashed');
	Route::post('trashAll',						'RecipesController@trashAll')					->name('recipes.trashAll');
	Route::delete('deleteTrashed/{id}',		'RecipesController@deleteTrashed')			->name('recipes.deleteTrashed');
	Route::post('deleteAll',					'RecipesController@deleteAll')				->name('recipes.deleteAll');

	Route::get('{id}/addFavorite',			'RecipesController@addFavorite')				->name('recipes.addFavorite');
	Route::get('{id}/removeFavorite',		'RecipesController@removeFavorite')			->name('recipes.removeFavorite');
	Route::get('{id}/makePrivate',			'RecipesController@makePrivate')				->name('recipes.makePrivate');
	Route::get('{id}/removePrivate',			'RecipesController@removePrivate')			->name('recipes.removePrivate');
	Route::get('{id}/duplicate',				'RecipesController@duplicate')				->name('recipes.duplicate');
	Route::post('{id}/storeComment',			'RecipesController@storeComment')			->name('recipes.storeComment');
	Route::get('{year}/{month}',			   'RecipesController@archive')     			->name('recipes.archive');
	
});
<file_sep><?php

// POSTS
Route::get('post/{id}',        ['uses' => 'PostsController@show',            'as' => 'posts.show']);

Route::group(['prefix'=>'posts'], function()
{
	$c = 'PostsController@';
	$r = 'posts.';

   Route::get('newPosts',                 ['uses' => $c . 'newPosts',            'as' => $r . 'newPosts']);

   Route::get('create',                   ['uses' => $c . 'create',              'as' => $r . 'create']);
   Route::post('store',                   ['uses' => $c . 'store',               'as' => $r . 'store']);
   Route::get('{key?}',                   ['uses' => $c . 'index',               'as' => $r . 'index']);
   Route::get('{id}/edit',                ['uses' => $c . 'edit',                'as' => $r . 'edit']);
   Route::put('{id}',                     ['uses' => $c . 'update',              'as' => $r . 'update']);
   Route::delete('{id}',                  ['uses' => $c . 'destroy',             'as' => $r . 'destroy']);

});
<file_sep><?php

// PHOTOS

// Route::group(['prefix'=>'backend/photos'], function()
// {
// 	$c = 'Backend\PhotosController@';
// 	$r = 'backend.photos.';

// 	Route::get('create/{album_id}',					['uses' => $c . 'create',					'as' => $r . 'create']);
// 	Route::post('store',									['uses' => $c . 'store',					'as' => $r . 'store']);
// 	Route::get('{id}',									['uses' => $c . 'show',						'as' => $r . 'show']);
// 	Route::delete('{id}',								['uses' => $c . 'destroy',					'as' => $r . 'delete']);

// });<file_sep><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Storage;
use App\Album;
use App\Photo;
use Session;
use Image;
use File;
use DB;
use Auth;

use App\Http\Requests\CreateAlbumRequest;
use App\Http\Requests\UpdateAlbumRequest;

class AlbumsController extends Controller
{

##################################################################################################################
#  ██████╗ ██████╗ ███╗   ██╗███████╗████████╗██████╗ ██╗   ██╗ ██████╗████████╗
# ██╔════╝██╔═══██╗████╗  ██║██╔════╝╚══██╔══╝██╔══██╗██║   ██║██╔════╝╚══██╔══╝
# ██║     ██║   ██║██╔██╗ ██║███████╗   ██║   ██████╔╝██║   ██║██║        ██║   
# ██║     ██║   ██║██║╚██╗██║╚════██║   ██║   ██╔══██╗██║   ██║██║        ██║   
# ╚██████╗╚██████╔╝██║ ╚████║███████║   ██║   ██║  ██║╚██████╔╝╚██████╗   ██║   
#  ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝  ╚═════╝   ╚═╝   
##################################################################################################################
   public function __construct() {
      // only allow authenticated users to access these pages
      //$this->middleware('auth', ['except'=>['index','show']]);
      // changing auth to guest would only allow guests to access these pages
      // you can also restrict the actions by adding ['except' => 'name_of_action'] at the end
      // $this->middleware('auth');
      $this->middleware('auth', ['except'=>['index', 'show']]);

      //Log::useFiles(storage_path().'/logs/articles.log');
      //Log::useFiles(storage_path().'/logs/audits.log');
   }


##################################################################################################################
#  ██████╗██████╗ ███████╗ █████╗ ████████╗███████╗
# ██╔════╝██╔══██╗██╔════╝██╔══██╗╚══██╔══╝██╔════╝
# ██║     ██████╔╝█████╗  ███████║   ██║   █████╗  
# ██║     ██╔══██╗██╔══╝  ██╔══██║   ██║   ██╔══╝  
# ╚██████╗██║  ██║███████╗██║  ██║   ██║   ███████╗
#  ╚═════╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝   ╚═╝   ╚══════╝
// Show the form for creating a new resource
##################################################################################################################
   public function create() {
      return view('albums.create');
   }


##################################################################################################################
# ██████╗ ███████╗███████╗████████╗██████╗  ██████╗ ██╗   ██╗
# ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔══██╗██╔═══██╗╚██╗ ██╔╝
# ██║  ██║█████╗  ███████╗   ██║   ██████╔╝██║   ██║ ╚████╔╝ 
# ██║  ██║██╔══╝  ╚════██║   ██║   ██╔══██╗██║   ██║  ╚██╔╝  
# ██████╔╝███████╗███████║   ██║   ██║  ██║╚██████╔╝   ██║   
# ╚═════╝ ╚══════╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝    ╚═╝   
// Remove the specified resource from storage
// Used in the index page and trashAll action to soft delete multiple records
##################################################################################################################
   public function destroy($id) {
      
      $album = Album::find($id);
      //dd($album);
      foreach($album->photos as $photo) {
         unlink(public_path('_albums/images/' . $album->id . "/" . $photo->new_name));
         unlink(public_path('_albums/images/thumbs/' . $album->id . "/" . $photo->new_name));
         //Delete the photos of this album from the database
         $photo->delete();
      }

      // Delete the album cover image and it's thumbnail
      unlink(public_path('_albums/cover_images/' . $album->cover_image));
      unlink(public_path('_albums/cover_images/thumbs/' . $album->cover_image));
      
      // Delete the IMAGES/THUMBS folder matching the album id
      File::deleteDirectory(public_path('_albums/images/thumbs/' . $album->id));
      // Delete the IMAGES folder matching the album id
      File::deleteDirectory(public_path('_albums/images/' . $album->id));

      //Delete the album from the database
      $album->delete();

      Session::flash('success','Album and images deleted.');
      return redirect()->route('albums.index');
   }


##################################################################################################################
# ███████╗██████╗ ██╗████████╗
# ██╔════╝██╔══██╗██║╚══██╔══╝
# █████╗  ██║  ██║██║   ██║   
# ██╔══╝  ██║  ██║██║   ██║   
# ███████╗██████╔╝██║   ██║   
# ╚══════╝╚═════╝ ╚═╝   ╚═╝   
// Show the form for editing the specified resource
##################################################################################################################
   public function edit($id)
   {
      if(!checkACL('author')) {
         return view('errors.403');
      }

      // Find the article to edit
      $album = Album::findOrFail($id);

      // find all categories in the categories table and pass them to the view
      //$categories = Category::whereHas('module', function ($query) {
      //   $query->where('name', '=', 'articles');
      //})->get();

      // Create an empty array to store the categories
      //$cats = [];
      // Store the category values into the $cats array
      //foreach ($categories as $category) {
      //   $cats[$category->id] = $category->name;
      // }

      return view('albums.edit', compact('album'));
   }


##################################################################################################################
# ██╗███╗   ██╗██████╗ ███████╗██╗  ██╗
# ██║████╗  ██║██╔══██╗██╔════╝╚██╗██╔╝
# ██║██╔██╗ ██║██║  ██║█████╗   ╚███╔╝ 
# ██║██║╚██╗██║██║  ██║██╔══╝   ██╔██╗ 
# ██║██║ ╚████║██████╔╝███████╗██╔╝ ██╗
# ╚═╝╚═╝  ╚═══╝╚═════╝ ╚══════╝╚═╝  ╚═╝
// Display a list of resources
##################################################################################################################
   public function index() {
      $albums = Album::with('Photos')->paginate(8);
      //return view('backend.albums.index')->with('albums', $albums);
      return view('albums.index', compact('albums'));
   }


##################################################################################################################
# ███╗   ██╗███████╗██╗    ██╗     █████╗ ██╗     ██████╗ ██╗   ██╗███╗   ███╗███████╗
# ████╗  ██║██╔════╝██║    ██║    ██╔══██╗██║     ██╔══██╗██║   ██║████╗ ████║██╔════╝
# ██╔██╗ ██║█████╗  ██║ █╗ ██║    ███████║██║     ██████╔╝██║   ██║██╔████╔██║███████╗
# ██║╚██╗██║██╔══╝  ██║███╗██║    ██╔══██║██║     ██╔══██╗██║   ██║██║╚██╔╝██║╚════██║
# ██║ ╚████║███████╗╚███╔███╔╝    ██║  ██║███████╗██████╔╝╚██████╔╝██║ ╚═╝ ██║███████║
# ╚═╝  ╚═══╝╚══════╝ ╚══╝╚══╝     ╚═╝  ╚═╝╚══════╝╚═════╝  ╚═════╝ ╚═╝     ╚═╝╚══════╝
// Display a listing of the resource that were created since the user's last login.
##################################################################################################################
   public function newAlbums(Request $request, $key=null)
   {
      // if(!checkACL('guest')) {
      //     return view('errors.403');
      // }

      //$alphas = range('A', 'Z');
      $alphas = DB::table('albums')
         ->select(DB::raw('DISTINCT LEFT(name, 1) as letter'))
         ->where('created_at', '>=' , Auth::user()->last_login_date)
         //->where('user_id', '=', Auth::user()->id)
         // ->where('personal', '!=', 1)
         // ->where('published_at','!=', null)
         ->orderBy('letter')
         ->get();
      //dd($alphas);

      $letters = [];
      foreach($alphas as $alpha) {
        $letters[] = $alpha->letter;
      }

      // If $key value is passed
      if ($key) {
         // $albums = Album::with('photos','category')->newAlbums()
         $albums = Album::with('photos')->newAlbums()
            ->where('title', 'like', $key . '%')
            ->get();
         return view('albums.newAlbums', compact('albums','letters'));
      }

      // $albums = Album::with('photos','category')->newAlbums()->get();
      $albums = Album::with('photos')->newAlbums()->get();
      return view('albums.newAlbums', compact('albums','letters'));
   }


##################################################################################################################
# ███████╗██╗  ██╗ ██████╗ ██╗    ██╗
# ██╔════╝██║  ██║██╔═══██╗██║    ██║
# ███████╗███████║██║   ██║██║ █╗ ██║
# ╚════██║██╔══██║██║   ██║██║███╗██║
# ███████║██║  ██║╚██████╔╝╚███╔███╔╝
# ╚══════╝╚═╝  ╚═╝ ╚═════╝  ╚══╝╚══╝ 
// Display the specified resource
##################################################################################################################
   public function show($id) {
      $album = Album::with('Photos')->find($id);
      return view('albums.show', compact('album'));
   }


##################################################################################################################
# ███████╗████████╗ ██████╗ ██████╗ ███████╗
# ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
# ███████╗   ██║   ██║   ██║██████╔╝█████╗  
# ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝  
# ███████║   ██║   ╚██████╔╝██║  ██║███████╗
# ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
// Store a newly created resource in storage
##################################################################################################################
   // public function store(Request $request) {
   public function store(CreateAlbumRequest $request) {
      
      // Get the file object
      $file = $request->file('cover_image');

      // Get file name with extension
      $filenameWithExt = $request->file('cover_image')->getClientOriginalName();

      // Get just the filename
      $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);

      // Get the extension
      $extension = $request->file('cover_image')->getClientOriginalExtension();

      // Create the new filename
      $filenameToStore = $filename . '_' . time() . '.' . $extension;
      //return $filenameToStore;
      
      // Check if Gallery/Images folders exists
      if (!file_exists('_albums/cover_images')) {
         mkdir('_albums/cover_images', 0777, true);
      }

      // move the file to the correct location
      $file->move('_albums/cover_images', $filenameToStore);
      
      // Check if Thumbs folder exists under Images
      if (!file_exists('_albums/cover_images/thumbs')) {
         mkdir('_albums/cover_images/thumbs', 0777, true);
      }

      // Create thumbnail
      $thumb = Image::make('_albums/cover_images/' . $filenameToStore)
         ->resize(240,160)
         ->save('_albums/cover_images/thumbs/' . $filenameToStore, 60);

      //Create album
      $album = new Album;
         $album->name = $request->input('name');
         $album->description = $request->input('description');
         $album->cover_image = $filenameToStore;
      $album->save();

      Session::flash('success','Album created.');
      return redirect()->route('albums.index');
      

      // if ($request->get('action') == 'save') {
      //    // Just save the record
      //    return back()->withInput();
      //    //redirect(App\Request::url());
      // } elseif ($request->get('action') == 'save_and_close') {
      //    // Save the record, and redirect to index
      //    return redirect()->route('albums.index');
      // } elseif ($request->get('action') == 'save_and_new') {
      //    // Save the record, and redirect to create
      //    return redirect()->route('albums.create');
      // }
     
   }


##################################################################################################################
# ██╗   ██╗██████╗ ██████╗  █████╗ ████████╗███████╗
# ██║   ██║██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██╔════╝
# ██║   ██║██████╔╝██║  ██║███████║   ██║   █████╗  
# ██║   ██║██╔═══╝ ██║  ██║██╔══██║   ██║   ██╔══╝  
# ╚██████╔╝██║     ██████╔╝██║  ██║   ██║   ███████╗
#  ╚═════╝ ╚═╝     ╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚══════╝
// UPDATE :: Update the specified resource in storage
##################################################################################################################
   public function update(UpdateAlbumRequest $request, $id)
   {

      if($request->file('cover_image')) {
         $album = Album::find($id);
         // Delete the project cover image and it's thumbnail
         unlink(public_path('_albums/cover_images/' . $album->cover_image));
         unlink(public_path('_albums/cover_images/thumbs/' . $album->cover_image));

         // Get the file object
         $file = $request->file('cover_image');

         // Get file name with extension
         $filenameWithExt = $request->file('cover_image')->getClientOriginalName();

         // Get just the filename
         $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);

         // Get the extension
         $extension = $request->file('cover_image')->getClientOriginalExtension();

         // Create the new filename
         $filenameToStore = $filename . '_' . time() . '.' . $extension;
         //return $filenameToStore;
         
         // Check if Gallery/Images folders exists
         if (!file_exists('_albums/cover_images')) {
            mkdir('_albums/cover_images', 0777, true);
         }

         // move the file to the correct location
         $file->move('_albums/cover_images', $filenameToStore);
         
         // Check if Thumbs folder exists under Images
         if (!file_exists('_albums/cover_images/thumbs')) {
            mkdir('_albums/cover_images/thumbs', 0777, true);
         }

         // Create thumbnail
         $thumb = Image::make('_albums/cover_images/' . $filenameToStore)
            ->resize(240,160)
            ->save('_albums/cover_images/thumbs/' . $filenameToStore, 60);
      }

      $album = Album::findOrFail($id);
         $album->name             = $request->name;
         $album->description      = $request->description;
         if ($request->file('cover_image')) {
            $album->cover_image   = $filenameToStore;
         }
      $album->save();
      
      // Save entry to log file using built-in Monolog
      //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") UPDATED article (" . $article->id . ")\r\n",
      //    [json_decode($article, true)]
      //);

      Session::flash('success','The album has been updated successfully.');
      return redirect()->route('albums.show', $album);
   }











##################################################################################################################
#  █████╗ ██████╗ ██████╗     ██████╗ ██╗  ██╗ ██████╗ ████████╗ ██████╗ 
# ██╔══██╗██╔══██╗██╔══██╗    ██╔══██╗██║  ██║██╔═══██╗╚══██╔══╝██╔═══██╗
# ███████║██║  ██║██║  ██║    ██████╔╝███████║██║   ██║   ██║   ██║   ██║
# ██╔══██║██║  ██║██║  ██║    ██╔═══╝ ██╔══██║██║   ██║   ██║   ██║   ██║
# ██║  ██║██████╔╝██████╔╝    ██║     ██║  ██║╚██████╔╝   ██║   ╚██████╔╝
# ╚═╝  ╚═╝╚═════╝ ╚═════╝     ╚═╝     ╚═╝  ╚═╝ ╚═════╝    ╚═╝    ╚═════╝ 
// Show the form for creating a new resource
##################################################################################################################
   public function addPhoto($album_id) {
      return view('albums.photos.create', compact('album_id'));
   }


##################################################################################################################
# ██████╗  ██████╗ ██╗    ██╗███╗   ██╗██╗      ██████╗  █████╗ ██████╗ 
# ██╔══██╗██╔═══██╗██║    ██║████╗  ██║██║     ██╔═══██╗██╔══██╗██╔══██╗
# ██║  ██║██║   ██║██║ █╗ ██║██╔██╗ ██║██║     ██║   ██║███████║██║  ██║
# ██║  ██║██║   ██║██║███╗██║██║╚██╗██║██║     ██║   ██║██╔══██║██║  ██║
# ██████╔╝╚██████╔╝╚███╔███╔╝██║ ╚████║███████╗╚██████╔╝██║  ██║██████╔╝
# ╚═════╝  ╚═════╝  ╚══╝╚══╝ ╚═╝  ╚═══╝╚══════╝ ╚═════╝ ╚═╝  ╚═╝╚═════╝
// Download the specified resource to the local machine -> bypass save as dialog
##################################################################################################################
   public function download($pathToFile) {
      return response()->download($pathToFile);   
   }


##################################################################################################################
# ███████╗██╗  ██╗ ██████╗ ██╗    ██╗    ██████╗ ██╗  ██╗ ██████╗ ████████╗ ██████╗ 
# ██╔════╝██║  ██║██╔═══██╗██║    ██║    ██╔══██╗██║  ██║██╔═══██╗╚══██╔══╝██╔═══██╗
# ███████╗███████║██║   ██║██║ █╗ ██║    ██████╔╝███████║██║   ██║   ██║   ██║   ██║
# ╚════██║██╔══██║██║   ██║██║███╗██║    ██╔═══╝ ██╔══██║██║   ██║   ██║   ██║   ██║
# ███████║██║  ██║╚██████╔╝╚███╔███╔╝    ██║     ██║  ██║╚██████╔╝   ██║   ╚██████╔╝
# ╚══════╝╚═╝  ╚═╝ ╚═════╝  ╚══╝╚══╝     ╚═╝     ╚═╝  ╚═╝ ╚═════╝    ╚═╝    ╚═════╝
// Display the specified resource
##################################################################################################################
   public function showPhoto($id) {
      $photo = Photo::find($id);
      return view('albums.photos.show', compact('photo'));
   }


##################################################################################################################
# ███████╗████████╗ ██████╗ ██████╗ ███████╗    ██████╗ ██╗  ██╗ ██████╗ ████████╗ ██████╗ 
# ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝    ██╔══██╗██║  ██║██╔═══██╗╚══██╔══╝██╔═══██╗
# ███████╗   ██║   ██║   ██║██████╔╝█████╗      ██████╔╝███████║██║   ██║   ██║   ██║   ██║
# ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝      ██╔═══╝ ██╔══██║██║   ██║   ██║   ██║   ██║
# ███████║   ██║   ╚██████╔╝██║  ██║███████╗    ██║     ██║  ██║╚██████╔╝   ██║   ╚██████╔╝
# ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝    ╚═╝     ╚═╝  ╚═╝ ╚═════╝    ╚═╝    ╚═════╝ 
// Store a newly created resource in storage
##################################################################################################################
   public function storePhoto(Request $request) {
      $this->validate($request, [
         'ori_name' => 'required',
         'new_name' => 'image|max:1999'
      ]);

      // Get the file object
      $file = $request->file('photo');

      // Get file name with extension
      $filenameWithExt = $request->file('photo')->getClientOriginalName();

      // Get just the filename
      $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);

      // Get the extension
      $extension = $request->file('photo')->getClientOriginalExtension();

      // Create the new filename
      $filenameToStore = $filename . '_' . time() . '.' . $extension;

      // Upload image
      // Check if Gallery/Images folders exists
      if (!file_exists('_albums/images/'.$request->input('album_id'))) {
         mkdir('_albums/images/' . $request->input('album_id'), 0777, true);
      }

      // move the file to the correct location
      $file->move('_albums/images/' . $request->input('album_id') . "/", $filenameToStore);
      
      // Check if Thumbs folder exists under Images
      if (!file_exists('_albums/images/thumbs/'.$request->input('album_id'))) {
         mkdir('_albums/images/thumbs/' . $request->input('album_id'), 0777, true);
      }

      // Create thumbnail
      $thumb = Image::make('_albums/images/' . $request->input('album_id') . "/" . $filenameToStore)
         ->resize(240,160)
         ->save('_albums/images/thumbs/' . $request->input('album_id') . "/" . $filenameToStore, 60);


      //Create photo record in DB
      $photo = new Photo;
         $photo->album_id = $request->input('album_id');
         $photo->ori_name = $request->input('ori_name');
         $photo->new_name = $filenameToStore;            
         $photo->size = $request->file('photo')->getClientSize();
         $photo->description = $request->input('description');
      $photo->save();

      Session::flash('success','Photo uploaded.');
      return redirect('/albums/'. $request->input('album_id'));
   }


##################################################################################################################
# ██████╗ ███████╗██╗     ███████╗████████╗███████╗    ██████╗ ██╗  ██╗ ██████╗ ████████╗ ██████╗ 
# ██╔══██╗██╔════╝██║     ██╔════╝╚══██╔══╝██╔════╝    ██╔══██╗██║  ██║██╔═══██╗╚══██╔══╝██╔═══██╗
# ██║  ██║█████╗  ██║     █████╗     ██║   █████╗      ██████╔╝███████║██║   ██║   ██║   ██║   ██║
# ██║  ██║██╔══╝  ██║     ██╔══╝     ██║   ██╔══╝      ██╔═══╝ ██╔══██║██║   ██║   ██║   ██║   ██║
# ██████╔╝███████╗███████╗███████╗   ██║   ███████╗    ██║     ██║  ██║╚██████╔╝   ██║   ╚██████╔╝
# ╚═════╝ ╚══════╝╚══════╝╚══════╝   ╚═╝   ╚══════╝    ╚═╝     ╚═╝  ╚═╝ ╚═════╝    ╚═╝    ╚═════╝   
// Remove the specified resource from storage
// ???? Used in the index page and trashAll action to soft delete multiple records
##################################################################################################################
   public function destroyPhoto($id) {
      $photo = Photo::find($id);

      unlink(public_path('_albums/images/' . $photo->album->id . "/" . $photo->new_name));
      unlink(public_path('_albums/images/thumbs/' . $photo->album->id . "/" . $photo->new_name));
      $photo->delete();

      // Check if there are any files left in the folder, if not, delete the folder and thumbs folder
      if (count(glob('_albums/images/' . $photo->album->id . "/*")) === 0 ) { // empty
         // Delete the IMAGES/THUMBS folder matching the album id
         File::deleteDirectory(public_path('_albums/images/thumbs/' . $photo->album_id));
         // Delete the IMAGES folder matching the album id
         File::deleteDirectory(public_path('_albums/images/' . $photo->album_id));
      }
      
      Session::flash('success','Image deleted.');
      return redirect(route('albums.show', $photo->album_id));
   }




}
<file_sep><?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class InvoiceItem extends Model
{
	protected $table = 'invoiceItems';
	protected $dates = ['work_date'];

	protected $fillable = [
		'invoice_id',
		'product_id',
		'notes',
		'work_date',
		'quantity',
		'price',
		'total'
	];


	// public function getTotal() {
	// 	return $this->price * $this->quantity;
	// }

	// An item belongs to an invoice
	public function invoice()
	{
		return $this->belongsTo('App\Invoice');
	}

	public function product()
	{
		return $this->belongsTo('App\Product');
	}


}
<file_sep><?php

// PROFILE
Route::get('profile/pwdChange/{id}',      ['uses'=>'ProfileController@pwdChange',      'as'=>'profile.pwdChange']);
Route::get('profile/{id?}',               ['uses'=>'ProfileController@index',          'as'=>'profile']);
Route::get('profile/resetSettings/{id}',  ['uses'=>'ProfileController@resetSettings',  'as'=>'profile.resetSettings']);
Route::get('profile/deleteImage/{id}',    ['uses'=>'ProfileController@deleteImage',    'as'=>'profile.deleteImage']);
Route::get('profile/account/{id}',        ['uses'=>'ProfileController@acctUpdate',     'as'=>'profile.acctUpdate']);
Route::get('profile/settings/{id}',       ['uses'=>'ProfileController@settingsUpdate', 'as'=>'profile.settingsUpdate']);

Route::put('profile/{id}',                ['uses'=>'ProfileController@update',         'as'=>'profile.update']);

Route::post('profile/account/{id}',       ['uses'=>'ProfileController@updateAcct',     'as'=>'profile.updateAcct']);
Route::post('profile/changePassword',     ['uses'=>'ProfileController@changePassword', 'as'=>'profile.changePassword']);
Route::post('profile/settings/{id}',      ['uses'=>'ProfileController@updateSettings', 'as'=>'profile.updateSettings']);<file_sep><?php

// FRONTEND PROJECTS



Route::get('woodProjects/newWoodProjects',		'WoodProjectsController@newWoodProjects')		->name('woodProjects.newWoodProjects');
Route::get('woodProjects/create',					'WoodProjectsController@create')					->name('woodProjects.create');
Route::get('woodProjects/admin',						'WoodProjectsController@admin')					->name('woodProjects.admin');
Route::get('woodProjects/{id}',						'WoodProjectsController@show')					->name('woodProjects.show');
Route::get('woodProjects/{id}/edit',				'WoodProjectsController@edit')					->name('woodProjects.edit');
Route::get('woodProjects/{pid?}',					'WoodProjectsController@index')					->name('woodProjects.index');

Route::put('woodProjects/{id}',						'WoodProjectsController@update')					->name('woodProjects.update');

Route::post('woodProjects/{id}/storeComment',	'WoodProjectsController@storeComment')			->name('woodProjects.storeComment');
Route::post('woodProjects/store',					'WoodProjectsController@store')					->name('woodProjects.store');

Route::delete('woodProjects/{id}',					'WoodProjectsController@destroy')				->name('woodProjects.destroy');




Route::get('woodProjectImages/create/{project_id}',	'WoodProjectImagesController@create')		->name('woodProjectImages.create');
Route::post('woodProjectImages/store',						'WoodProjectImagesController@store')		->name('woodProjectImages.store');
Route::get('woodProjectImages/{id}',						'WoodProjectImagesController@show')			->name('woodProjectImages.show');
Route::get('woodProjectImages/{id}/manageImages',		'WoodProjectImagesController@index')		->name('woodProjectImages.index');
Route::delete('woodProjectImages/{id}',					'WoodProjectImagesController@destroy')		->name('woodProjectImages.destroy');

// Route::get('woodProjectImage/{id}',       ['uses'=>'WoodProjectImagesController@show',   'as'=>'woodProjectImage.show']);



// // BACKEND PROJECTS
// Route::group(['prefix'=>'backend/woodProjects'], function()
// {
// 	$c = 'Backend\WoodProjectsController@';
// 	$r = 'backend.woodProjects.';

// 	Route::get('admin',							['uses'=> $c . 'admin',					'as'=> $r . 'admin']);
// 	Route::get('newWoodProjects',	         ['uses'=> $c . 'newWoodProjects',	'as'=> $r . 'newWoodProjects']	);

// 	Route::get('',									['uses'=> $c . 'index',					'as'=> $r . 'index']);
// 	Route::get('create',							['uses'=> $c . 'create',				'as'=> $r . 'create']);
// 	Route::post('store',							['uses'=> $c . 'store',					'as'=> $r . 'store']);
// 	Route::get('{id}/edit',						['uses'=> $c . 'edit',					'as'=> $r . 'edit']);
// 	Route::put('{id}',							['uses'=> $c . 'update',				'as'=> $r . 'update']);
// 	Route::get('{id}',							['uses'=> $c . 'show',					'as'=> $r . 'show']);
// 	Route::delete('{id}',						['uses'=> $c . 'destroy',				'as'=> $r . 'delete']);

// });



// // PROJECT IMAGES
// Route::group(['prefix'=>'backend/woodProjectImages'], function()
// {
// 	$c = 'Backend\WoodProjectImagesController@';
// 	$r = 'backend.woodProjectImage.';

// 	Route::get('create/{project_id}',				['uses' => $c . 'create',					'as' => $r . 'create']);
// 	Route::post('store',									['uses' => $c . 'store',					'as' => $r . 'store']);
// 	Route::get('{id}',									['uses' => $c . 'show',						'as' => $r . 'show']);
// 	Route::delete('{id}',								['uses' => $c . 'destroy',					'as' => $r . 'delete']);

// });
<file_sep><?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Profile extends Model
{
   use SoftDeletes;

	public function user() { 
		return $this->belongsTo('App\User');
	}

   public function landingPage () {
      return $this->belongsTo(Category::class);
   }

   // public function scopeTrashed($query)
   // {
   //    return $query->where('deleted_at', '!=', NULL)->withTrashed();
   // }
}
<file_sep><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;
//use Charts;
use App\Album;
use App\Article;
use App\Category;
use App\Comment;
use App\Client;
use App\Invoice;
use App\InvoiceItem;
use App\Module;
use App\Post;
use App\Product;
use App\Recipe;
use App\Role;
use App\User;
use App\WoodProject;

class dashboardController extends Controller
{

##################################################################################################################
#  ██████╗ ██████╗ ███╗   ██╗███████╗████████╗██████╗ ██╗   ██╗ ██████╗████████╗
# ██╔════╝██╔═══██╗████╗  ██║██╔════╝╚══██╔══╝██╔══██╗██║   ██║██╔════╝╚══██╔══╝
# ██║     ██║   ██║██╔██╗ ██║███████╗   ██║   ██████╔╝██║   ██║██║        ██║   
# ██║     ██║   ██║██║╚██╗██║╚════██║   ██║   ██╔══██╗██║   ██║██║        ██║   
# ╚██████╗╚██████╔╝██║ ╚████║███████║   ██║   ██║  ██║╚██████╔╝╚██████╗   ██║   
#  ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝  ╚═════╝   ╚═╝   
##################################################################################################################
	public function __construct() {
		$this->middleware('auth')->except(['invoicer_dashboard']);
		//Log::useFiles(storage_path().'/logs/articles.log');
		//Log::useFiles(storage_path().'/logs/audits.log');
	}


##################################################################################################################
# ██╗███╗   ██╗██████╗ ███████╗██╗  ██╗
# ██║████╗  ██║██╔══██╗██╔════╝╚██╗██╔╝
# ██║██╔██╗ ██║██║  ██║█████╗   ╚███╔╝ 
# ██║██║╚██╗██║██║  ██║██╔══╝   ██╔██╗ 
# ██║██║ ╚████║██████╔╝███████╗██╔╝ ██╗
# ╚═╝╚═╝  ╚═══╝╚═════╝ ╚══════╝╚═╝  ╚═╝
// Display a list of resources
##################################################################################################################
	public function index()
	{
		$roles = Role::where('id','<=',70)->orderBy('name','asc')->pluck('display_name','id');

		$newAlbums = Album::where('created_at', '>=' , Auth::user()->last_login_date)->get();
		$newArticles = Article::with('user')->where('created_at', '>=' , Auth::user()->last_login_date)->get();
		$newCategories = Category::where('created_at', '>=' , Auth::user()->last_login_date)->get();
		$newComments = Comment::where('created_at', '>=' , Auth::user()->last_login_date)->get();
		$newModules = Module::where('created_at', '>=' , Auth::user()->last_login_date)->get();
		$newPosts = Post::with('user')->where('created_at', '>=' , Auth::user()->last_login_date)->get();
		$newRecipes = Recipe::with('user')->where('created_at', '>=' , Auth::user()->last_login_date)->get();
		$newRoles = Role::where('created_at', '>=' , Auth::user()->last_login_date)->get();
		$newUsers = User::where('created_at', '>=' , Auth::user()->last_login_date)->get();
		$newWoodProjects = WoodProject::where('created_at', '>=' , Auth::user()->last_login_date)->get();
		

		return view('dashboard', compact('newAlbums','newArticles','newCategories','newComments','newModules','newPosts','newRecipes','newRoles','roles','newUsers','newWoodProjects'));
	}


##################################################################################################################
# ██████╗  ██████╗ ███████╗████████╗███████╗
# ██╔══██╗██╔═══██╗██╔════╝╚══██╔══╝██╔════╝
# ██████╔╝██║   ██║███████╗   ██║   ███████╗
# ██╔═══╝ ██║   ██║╚════██║   ██║   ╚════██║
# ██║     ╚██████╔╝███████║   ██║   ███████║
# ╚═╝      ╚═════╝ ╚══════╝   ╚═╝   ╚══════╝
##################################################################################################################
	public function posts()
	{
		return view('posts.index');
	}


##################################################################################################################
# ██╗████████╗███████╗███╗   ███╗███████╗
# ██║╚══██╔══╝██╔════╝████╗ ████║██╔════╝
# ██║   ██║   █████╗  ██╔████╔██║███████╗
# ██║   ██║   ██╔══╝  ██║╚██╔╝██║╚════██║
# ██║   ██║   ███████╗██║ ╚═╝ ██║███████║
# ╚═╝   ╚═╝   ╚══════╝╚═╝     ╚═╝╚══════╝
##################################################################################################################
	public function items()
	{
		return view('items.index');
	}


##################################################################################################################
# ██████╗ ███████╗ ██████╗██╗██████╗ ███████╗███████╗
# ██╔══██╗██╔════╝██╔════╝██║██╔══██╗██╔════╝██╔════╝
# ██████╔╝█████╗  ██║     ██║██████╔╝█████╗  ███████╗
# ██╔══██╗██╔══╝  ██║     ██║██╔═══╝ ██╔══╝  ╚════██║
# ██║  ██║███████╗╚██████╗██║██║     ███████╗███████║
# ╚═╝  ╚═╝╚══════╝ ╚═════╝╚═╝╚═╝     ╚══════╝╚══════╝
##################################################################################################################
	public function recipes()
	{
		return view('recipes.index');
	}


##################################################################################################################
# ██████╗ ██████╗  ██████╗ ██████╗ ██╗   ██╗ ██████╗████████╗███████╗
# ██╔══██╗██╔══██╗██╔═══██╗██╔══██╗██║   ██║██╔════╝╚══██╔══╝██╔════╝
# ██████╔╝██████╔╝██║   ██║██║  ██║██║   ██║██║        ██║   ███████╗
# ██╔═══╝ ██╔══██╗██║   ██║██║  ██║██║   ██║██║        ██║   ╚════██║
# ██║     ██║  ██║╚██████╔╝██████╔╝╚██████╔╝╚██████╗   ██║   ███████║
# ╚═╝     ╚═╝  ╚═╝ ╚═════╝ ╚═════╝  ╚═════╝  ╚═════╝   ╚═╝   ╚══════╝
##################################################################################################################
	public function products()
	{
		return view('products.index');
	}


	public function invoicer_dashboard() 
	{
      $clients = Client::all();
      $invoices = Invoice::all();
      $invoiceItems = InvoiceItem::all();
      $products = Product::all();
      
		return view('invoicer.dashboard.index', compact('clients', 'invoices', 'invoiceItems', 'products'));
	}


}<file_sep><?php

// GALLERY

Route::group(['prefix'=>'backend/gallery'], function()
{
	$c = 'Backend\GalleryController@';
	$r = 'backend.gallery.';

	Route::get('list',							['uses' => $c . 'viewGalleryList',			'as' => $r . 'list']);
	Route::post('save',							['uses' => $c . 'saveGallery',				'as' => $r . 'save']);
	Route::get('view/{id}',						['uses' => $c . 'viewGalleryPics',			'as' => $r . 'view']);
	Route::post('do-upload',					['uses' => $c . 'doImageUpload',				'as' => $r . 'do-upload']);
	Route::delete('delete/{id}',				['uses' => $c . 'deleteGallery',				'as' => $r . 'delete']);
	Route::get('edit/{id}',						['uses' => $c . 'editGallery',				'as' => $r . 'edit']);
	Route::put('{id}',							['uses' => $c . 'updateGallery',				'as' => $r . 'update']);

});<file_sep><?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\SoftDeletes;

use App\Profile;
use Auth;

class User extends Authenticatable
{
	use Notifiable;
	use SoftDeletes;

	/**
	 * The attributes that are mass assignable.
	 *
	 * @var array
	 */
	protected $fillable = [
		'username', 'email', 'publicEmail', 'password',
	];

	protected $dates = ['last_login_date'];

	/**
	 * The attributes that should be hidden for arrays.
	 *
	 * @var array
	 */
	protected $hidden = [
		'password', 'remember_token',
	];

	/**
	* Always capitalize the first name when we retrieve it
	*/
	public function getFirstNameAttribute($value) {
		return ucfirst($value);
	}

	/**
	 * Always capitalize the last name when we retrieve it
	 */
	public function getLastNameAttribute($value) {
		return ucfirst($value);
	}

	/**
	* Always capitalize the first letter of the username when we retrieve it
	*/
	public function getUsernameAttribute($value) {
		return ucfirst($value);
	}
	
	public function profile()
	{
		return $this->hasOne('App\Profile')->withTrashed();
	}

	public function role()
	{
		return $this->belongsTo('App\Role')->orderBy('name', 'asc');
	}

	public function recipes()
	{
		return $this->belongsToMany('App\Recipe');
	}

   public function dartScores()
   {
      return $this->belongsToMany('App\DartScore');
   }

   public function dartgames()
   {
      return $this->belongsToMany('App\DartGame');
   }

   public function scopeTrashed($query)
   {
      return $query->where('deleted_at', '!=', NULL)->withTrashed();
   }

   public function scopeNewUsers($query)
   {
      return $query
         ->where('created_at', '>=' , Auth::user()->last_login_date)
         //->where('user_id', '=', Auth::user()->id)
         ->orderBy('username','DESC');
   }

   public function scopeInactiveUsers($query)
   {
      return $query
         ->where('login_count', '=' , 0)
         //->where('user_id', '=', Auth::user()->id)
         ->orderBy('username','DESC');
   }


}
<file_sep><?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Dart extends Model
{
   protected $table = "dartgames";

   protected $fillable = [
      'type',
      't1_players',
      't2_players',
      'ind_players',
      'status'      
   ];

   // protected $casts = [
   //    'team1players' => 'array',
   //    'team2players' => 'array'
   // ];

   // public function team1players()
   // {
   //    return $this->hasMany('App\User');
   // }

   // public function team2players()
   // {
   //    return $this->hasMany('App\User');
   // }

   public function users()
   {
      return $this->belongsToMany('App\User');
   }
}
<file_sep><?php

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        // $this->call(UsersTableSeeder::class);
        $this->call('RolesTableSeeder');
        $this->call('UsersTableSeeder');
        $this->call('ModulesTableSeeder');
        $this->call('CategoriesTableSeeder');
        $this->call('ArticlesTableSeeder');
        $this->call(ProfilesTableSeeder::class);
        $this->call(PostsTableSeeder::class);
        $this->call(ModulesTableSeeder::class);
        $this->call(CategoriesTableSeeder::class);
        $this->call(ArticlesTableSeeder::class);
        $this->call(ImageWoodprojectTableSeeder::class);
        $this->call(WoodprojectsTableSeeder::class);
        $this->call(RecipesTableSeeder::class);
        $this->call(RecipeUserTableSeeder::class);
        $this->call(AlbumsTableSeeder::class);
        $this->call(ArticleUserTableSeeder::class);
        $this->call(GalleryTableSeeder::class);
        $this->call(ImagesTableSeeder::class);
        $this->call(PhotosTableSeeder::class);
        $this->call(CommentsTableSeeder::class);
        $this->call(TagsTableSeeder::class);
        $this->call(PostTagTableSeeder::class);
    }
}
<file_sep><?php

// USERS
Route::group(['prefix'=>'users'], function()
{

	Route::get('trashed',							'UsersController@trashed')					->name('users.trashed');
	Route::get('showTrashed/{id}',				'UsersController@showTrashed')			->name('users.showTrashed');
	Route::get('restore/{id}',						'UsersController@restore')					->name('users.restore');
	Route::get('resetPwd/{id}',					'UsersController@resetPwd')				->name('users.resetPwd');
	Route::get('newUsers/{id?}',					'UsersController@newUsers')				->name('users.newUsers');
	Route::get('inactiveUsers/{id?}',			'UsersController@inactiveUsers')			->name('users.inactiveUsers');

	Route::post('restoreAll',              	'UsersController@restoreAll')       	->name('users.restoreAll');
	Route::post('trashAll',                	'UsersController@trashAll')    		   ->name('users.trashAll');
	Route::post('deleteAll',            	   'UsersController@deleteAll') 	         ->name('users.deleteAll');
	Route::post('changePassword/{id}',			'UsersController@changePassword')		->name('users.changePassword');

	Route::delete('deleteTrashed/{id}',			'UsersController@deleteTrashed')			->name('users.deleteTrashed');

	
	
	Route::get('create',								'UsersController@create')					->name('users.create');
	Route::post('',									'UsersController@store')					->name('users.store');
	Route::get('{id}/show',							'UsersController@show')						->name('users.show');
	Route::get('{key?}',								'UsersController@index')					->name('users.index');
	Route::get('{id}/edit',							'UsersController@edit')						->name('users.edit');
	Route::put('{id}',								'UsersController@update')					->name('users.update');
	Route::delete('{id}',							'UsersController@destroy')					->name('users.destroy');
});

// Route::resource('users', 'UsersController', ['parameters' => [
//     'index' => 'key'
// ]]);<file_sep><?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
//use OwenIt\Auditing\Auditable;
//use OwenIt\Auditing\Contracts\Auditable as AuditableContract;
use Auth;
use App\Category;
use Carbon\Carbon;


class Article extends Model
	// implements AuditableContract
{
	use SoftDeletes;
	//use Auditable;

	protected $dates = ['deleted_at', 'published_at'];

	protected $fillable = [
		'title',
		'category_id',
		'published_at',
		'description_eng',
		'description_fre',
		'user_id'
	];


	public function comments()
	{
		return $this->morphMany('\App\Comment', 'commentable')->orderBy('id','desc');
	}
	
	public function user()
	{
		return $this->belongsTo('App\User');
	}

	public function category()
	{
		return $this->belongsTo('App\Category');
	}

	// Used to display the Add/Remove links if item is in favorite list
	public function favorites()
	{
		return $this->belongsToMany('App\User')->where('user_id','=',Auth::user()->id);
	}

	public function scopePublished($query)
	{
		return $query->where('published_at', '<', Carbon::now());
	}

	public function scopeMyArticles($query)
	{
		return $query->where('user_id', '=', Auth::user()->id)->orderBy('title','DESC');
	}

	public function scopeUnpublished($query)
	{
		return $query->whereNull('published_at');
	}

	public function scopeFuture($query)
	{
		return $query->where('published_at', '>', Carbon::Now());
	}
	
	public function scopeTrashed($query)
	{
		return $query->whereNotNull('deleted_at')->withTrashed();
	}

	public function scopeTrashedCount($query)
	{
		return $query->whereNotNull('deleted_at')->withTrashed();
	}

   public function scopeNewArticles($query)
   {
      return $query
         ->where('created_at', '>=' , Auth::user()->last_login_date)
         ->orderBy('title','DESC');
   }

	// public function scopeMyFavorites($query)
	// {
	// 	return $query->whereHas('user', function($q) 
	// 	{
	// 		$q->where('user_id', '=', Auth::user()->id);
	// 		dd($q);
	// 	})->get();
	// 	return $query->wherePivot('article_user', Auth::user()->id);
	// }


}
<file_sep><?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateWoodProjectsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('woodprojects', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('category_id')->unsigned();
            $table->string('name');
            $table->text('description');
            $table->string('main_image');
            $table->integer('views')->unsigned()->default(0);
            $table->integer('time_invested')->unsigned()->nullable();;
            $table->integer('price')->unsigned()->nullable();
            $table->string('wood_specie_id')->nullable();
            $table->string('wood_type_id')->nullable();
            $table->integer('width')->unsigned()->nullable();
            $table->integer('depth')->unsigned()->nullable();
            $table->integer('height')->unsigned()->nullable();
            $table->string('stain_type_id')->nullable();
            $table->string('stain_color_id')->nullable();
            $table->string('stain_sheen_id')->nullable();
            $table->string('finish_type_id')->nullable();
            $table->string('finish_sheen_id')->nullable();
            $table->integer('weight')->unsigned()->nullable();
            $table->timestamps();
            $table->dateTime('completed_at')->nullable();

            // Add foreign key in the database manually
            $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('woodprojects');
    }
}
<file_sep><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Client;
use Config;
use Session;


class ClientsController extends Controller
{

	public function index()
	{
		$clients = Client::sortable()
			->orderBy('company_name','asc')
			->paginate(Config::get('settings.rowsPerPage'));
		return view('invoicer.clients.index', compact('clients'));
	}


	public function create()
	{
		return view('invoicer.clients.create');
	}


	public function store(Request $request)
	{
		// validate the data
		$this->validate($request, array(
			'company_name' => 'required',
			'contact_name' => 'required',
		));

		// save the data in the database
		$client = new client;
			$client->company_name = $request->company_name;
			$client->contact_name = $request->contact_name;
			$client->address = $request->address;
			$client->city = $request->city;
			$client->state = $request->state;
			$client->zip = $request->zip;
			$client->notes = $request->notes;
			$client->telephone = $request->telephone;
			$client->cell = $request->cell;
			$client->fax = $request->fax;
			$client->email = $request->email;
			$client->website = $request->website;
		$client->save();

		// set a flash message to be displayed on screen
		Session::flash('success','The client was successfully saved!');

		// redirect to another page
	   return redirect()->route('invoicer.clients.index');
	}


	public function show($id)
	{
		$client = Client::findOrFail($id);
		return view('invoicer.clients.show', compact('client'));
	}


	public function edit($id)
	{
		$client = Client::findOrFail($id);
		return view('invoicer.clients.edit', compact('client'));
	}


	public function update(Request $request, $id)
	{
		// validate the data
		$this->validate($request, array(
			'company_name' => 'required',
			'contact_name' => 'required',
		));

		$client = Client::find($id);
			$client->company_name = $request->company_name;
			$client->contact_name = $request->contact_name;
			$client->address = $request->address;
			$client->city = $request->city;
			$client->state = $request->state;
			$client->zip = $request->zip;
			$client->notes = $request->notes;
			$client->telephone = $request->telephone;
			$client->cell = $request->cell;
			$client->fax = $request->fax;
			$client->email = $request->email;
			$client->website = $request->website;
		$client->save();
		
		// Set flash data with success message
		Session::flash ('success', 'The client was successfully updated!');

		// Redirect
		return redirect()->route('invoicer.clients.index');
	}


	public function destroy($id)
	{
		$client = Client::find($id);
		$client->delete();

		// Set flash data with success message
		Session::flash('success','The client was deleted successfully.');

		// Redirect
		return redirect()->route('invoicer.clients.index');
	}
	

	public function search(Request $request)
	{
		//dd($request->q);
		if($request->selection == 'company') {
			$clients = Client::where('company_name', 'like', '%' . $request->searchWord . '%')->paginate(10);
		}

		if($request->selection == 'contact') {
			$clients = Client::where('contact_name', 'like', '%' . $request->searchWord . '%')->paginate(10);
		}
		
		return view('invoicer.clients.index', compact('clients'));
	}
	
}
<file_sep><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use App\Category;
use App\Comment;
use App\WoodProject;
use Auth;
use DB;
use File;
use Image;
use Route;
use Session;

use App\Http\Requests\CreateWoodProjectRequest;
use App\Http\Requests\UpdateWoodProjectRequest;
use App\Http\Requests\CreateCommentRequest;

class WoodProjectsController extends Controller
{

##################################################################################################################
#  ██████╗ ██████╗ ███╗   ██╗███████╗████████╗██████╗ ██╗   ██╗ ██████╗████████╗
# ██╔════╝██╔═══██╗████╗  ██║██╔════╝╚══██╔══╝██╔══██╗██║   ██║██╔════╝╚══██╔══╝
# ██║     ██║   ██║██╔██╗ ██║███████╗   ██║   ██████╔╝██║   ██║██║        ██║   
# ██║     ██║   ██║██║╚██╗██║╚════██║   ██║   ██╔══██╗██║   ██║██║        ██║   
# ╚██████╗╚██████╔╝██║ ╚████║███████║   ██║   ██║  ██║╚██████╔╝╚██████╗   ██║   
#  ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝  ╚═════╝   ╚═╝   
##################################################################################################################


##################################################################################################################
#  █████╗ ██████╗ ███╗   ███╗██╗███╗   ██╗
# ██╔══██╗██╔══██╗████╗ ████║██║████╗  ██║
# ███████║██║  ██║██╔████╔██║██║██╔██╗ ██║
# ██╔══██║██║  ██║██║╚██╔╝██║██║██║╚██╗██║
# ██║  ██║██████╔╝██║ ╚═╝ ██║██║██║ ╚████║
# ╚═╝  ╚═╝╚═════╝ ╚═╝     ╚═╝╚═╝╚═╝  ╚═══╝
##################################################################################################################
	public function admin() {
		return view('woodProjects.admin.index');
	}


##################################################################################################################
#  ██████╗██████╗ ███████╗ █████╗ ████████╗███████╗
# ██╔════╝██╔══██╗██╔════╝██╔══██╗╚══██╔══╝██╔════╝
# ██║     ██████╔╝█████╗  ███████║   ██║   █████╗  
# ██║     ██╔══██╗██╔══╝  ██╔══██║   ██║   ██╔══╝  
# ╚██████╗██║  ██║███████╗██║  ██║   ██║   ███████╗
#  ╚═════╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝   ╚═╝   ╚══════╝
// Show the form for creating a new resource
##################################################################################################################
	public function create()
	{
		// find all projects categories in the categories table and pass them to the view
		$categories = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'wood projects');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$cats = [];

		// Store the category values into the $cats array
		foreach ($categories as $category) {
			$cats[$category->id] = $category->name;
		}

		// find all stain colors categories in the categories table and pass them to the view
		$stainColors = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'stain color');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$staincolors = [];

		// Store the category values into the $cats array
		foreach ($stainColors as $stainColor) {
			$staincolors[$stainColor->id] = $stainColor->name;
		}

		// find all stain sheens categories in the categories table and pass them to the view
		$stainSheens = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'stain sheen');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$stainsheens = [];

		// Store the category values into the $cats array
		foreach ($stainSheens as $stainSheen) {
			$stainsheens[$stainSheen->id] = $stainSheen->name;
		}

		// find all stain types categories in the categories table and pass them to the view
		$stainTypes = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'stain type');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$staintypes = [];

		// Store the category values into the $cats array
		foreach ($stainTypes as $stainType) {
			$staintypes[$stainType->id] = $stainType->name;
		}

		// find all wood species categories in the categories table and pass them to the view
		$woodSpecies = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'wood specie');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$woodspecies = [];

		// Store the category values into the $cats array
		foreach ($woodSpecies as $woodSpecie) {
			$woodspecies[$woodSpecie->id] = $woodSpecie->name;
		}

		// find all wood types categories in the categories table and pass them to the view
		$woodTypes = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'wood type');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$woodtypes = [];

		// Store the category values into the $cats array
		foreach ($woodTypes as $woodType) {
			$woodtypes[$woodType->id] = $woodType->name;
		}

		// find all wood types categories in the categories table and pass them to the view
		$finishTypes = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'finish type');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$finishtypes = [];

		// Store the category values into the $cats array
		foreach ($finishTypes as $finishType) {
			$finishtypes[$finishType->id] = $finishType->name;
		}

		// find all stain sheens categories in the categories table and pass them to the view
		$finishSheens = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'finish sheen');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$finishsheens = [];

		// Store the category values into the $cats array
		foreach ($finishSheens as $finishSheen) {
			$finishsheens[$finishSheen->id] = $finishSheen->name;
		}

		return view('woodProjects.create')
			->withCategories($cats)
			->withWoodSpecies($woodspecies)
			->withWoodTypes($woodtypes)
			->withStainTypes($staintypes)
			->withStainColors($staincolors)
			->withStainSheens($stainsheens)
			->withFinishTypes($finishtypes)
			->withFinishSheens($finishsheens)
		;
	}


##################################################################################################################
# ██████╗ ███████╗███████╗████████╗██████╗  ██████╗ ██╗   ██╗
# ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔══██╗██╔═══██╗╚██╗ ██╔╝
# ██║  ██║█████╗  ███████╗   ██║   ██████╔╝██║   ██║ ╚████╔╝ 
# ██║  ██║██╔══╝  ╚════██║   ██║   ██╔══██╗██║   ██║  ╚██╔╝  
# ██████╔╝███████╗███████║   ██║   ██║  ██║╚██████╔╝   ██║   
# ╚═════╝ ╚══════╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝    ╚═╝   
// Remove the specified resource from storage
// Used in the index page and trashAll action to soft delete multiple records
##################################################################################################################
	public function destroy($id) {
		
		$project = WoodProject::find($id);
		//dd($project);
		foreach($project->projectImages as $photo) {
			unlink(public_path('_woodProjects/images/' . $project->id . "/" . $photo->new_name));
			unlink(public_path('_woodProjects/images/thumbs/' . $project->id . "/" . $photo->new_name));
			//Delete the photos of this project from the database
			$photo->delete();
		}

		// Delete the project cover image and it's thumbnail
		unlink(public_path('_woodProjects/main_images/' . $project->main_image));
		unlink(public_path('_woodProjects/main_images/thumbs/' . $project->main_image));
		
		// Delete the IMAGES/THUMBS folder matching the project id
		File::deleteDirectory(public_path('_woodProjects/images/thumbs/' . $project->id));
		// Delete the IMAGES folder matching the project id
		File::deleteDirectory(public_path('_woodProjects/images/' . $project->id));

		//Delete the project from the database
		$project->delete();

		Session::flash('success','Project and associated images have been deleted.');
		return redirect()->route('woodProjects.index');
	}


##################################################################################################################
# ███████╗██████╗ ██╗████████╗
# ██╔════╝██╔══██╗██║╚══██╔══╝
# █████╗  ██║  ██║██║   ██║   
# ██╔══╝  ██║  ██║██║   ██║   
# ███████╗██████╔╝██║   ██║   
# ╚══════╝╚═════╝ ╚═╝   ╚═╝   
// Show the form for editing the specified resource
##################################################################################################################
	public function edit($id)
	{
		$project = WoodProject::find($id);

		// find all projects categories in the categories table and pass them to the view
		$categories = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'wood projects');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$cats = [];

		// Store the category values into the $cats array
		foreach ($categories as $category) {
			$cats[$category->id] = $category->name;
		}

		// find all stain colors categories in the categories table and pass them to the view
		$stainColors = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'stain color');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$staincolors = [];

		// Store the category values into the $cats array
		foreach ($stainColors as $stainColor) {
			$staincolors[$stainColor->id] = $stainColor->name;
		}

		// find all stain sheens categories in the categories table and pass them to the view
		$stainSheens = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'stain sheen');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$stainsheens = [];

		// Store the category values into the $cats array
		foreach ($stainSheens as $stainSheen) {
			$stainsheens[$stainSheen->id] = $stainSheen->name;
		}

		// find all stain types categories in the categories table and pass them to the view
		$stainTypes = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'stain type');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$staintypes = [];

		// Store the category values into the $cats array
		foreach ($stainTypes as $stainType) {
			$staintypes[$stainType->id] = $stainType->name;
		}

		// find all wood species categories in the categories table and pass them to the view
		$woodSpecies = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'wood specie');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$woodspecies = [];

		// Store the category values into the $cats array
		foreach ($woodSpecies as $woodSpecie) {
			$woodspecies[$woodSpecie->id] = $woodSpecie->name;
		}

		// find all wood types categories in the categories table and pass them to the view
		$woodTypes = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'wood type');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$woodtypes = [];

		// Store the category values into the $cats array
		foreach ($woodTypes as $woodType) {
			$woodtypes[$woodType->id] = $woodType->name;
		}

		// find all wood types categories in the categories table and pass them to the view
		$finishTypes = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'finish type');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$finishtypes = [];

		// Store the category values into the $cats array
		foreach ($finishTypes as $finishType) {
			$finishtypes[$finishType->id] = $finishType->name;
		}

		// find all stain sheens categories in the categories table and pass them to the view
		$finishSheens = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'finish sheen');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$finishsheens = [];

		// Store the category values into the $cats array
		foreach ($finishSheens as $finishSheen) {
			$finishsheens[$finishSheen->id] = $finishSheen->name;
		}
		
		return view('woodProjects.edit', compact('project'))
			->withCategories($cats)
			->withWoodSpecies($woodspecies)
			->withWoodTypes($woodtypes)
			->withStainTypes($staintypes)
			->withStainColors($staincolors)
			->withStainSheens($stainsheens)
			->withFinishTypes($finishtypes)
			->withFinishSheens($finishsheens)
		;
	}


##################################################################################################################
# ██╗███╗   ██╗██████╗ ███████╗██╗  ██╗
# ██║████╗  ██║██╔══██╗██╔════╝╚██╗██╔╝
# ██║██╔██╗ ██║██║  ██║█████╗   ╚███╔╝ 
# ██║██║╚██╗██║██║  ██║██╔══╝   ██╔██╗ 
# ██║██║ ╚████║██████╔╝███████╗██╔╝ ██╗
# ╚═╝╚═╝  ╚═══╝╚═════╝ ╚══════╝╚═╝  ╚═╝
// Display a list of resources
##################################################################################################################
	public function index()
	{
		//$projects = Project::with('Images')->get();
		// $projects = WoodProject::orderBy('name','asc')->get();
		$projects = WoodProject::orderBy('name','asc')->paginate(8);
		//dd($projects);
		return view('woodProjects.index', compact('projects'));
	}


##################################################################################################################
#
#
# MANAGE IMAGES
#
#
#
// Display a list of resources
##################################################################################################################
	// public function manageImages($id)
	// {
	// 	//$projects = Project::with('Images')->get();
	// 	// $projects = WoodProject::orderBy('name','asc')->get();
	// 	//$projects = WoodProject::orderBy('name','asc')->paginate(8);
	// 	//dd($projects);
	// 	$project = WoodProject::find($id);
	// 	return view('woodProjects.manageImages', compact('project'));
	// }


##################################################################################################################
# ███╗   ██╗███████╗██╗    ██╗    ██████╗ ██████╗  ██████╗      ██╗███████╗ ██████╗████████╗███████╗
# ████╗  ██║██╔════╝██║    ██║    ██╔══██╗██╔══██╗██╔═══██╗     ██║██╔════╝██╔════╝╚══██╔══╝██╔════╝
# ██╔██╗ ██║█████╗  ██║ █╗ ██║    ██████╔╝██████╔╝██║   ██║     ██║█████╗  ██║        ██║   ███████╗
# ██║╚██╗██║██╔══╝  ██║███╗██║    ██╔═══╝ ██╔══██╗██║   ██║██   ██║██╔══╝  ██║        ██║   ╚════██║
# ██║ ╚████║███████╗╚███╔███╔╝    ██║     ██║  ██║╚██████╔╝╚█████╔╝███████╗╚██████╗   ██║   ███████║
# ╚═╝  ╚═══╝╚══════╝ ╚══╝╚══╝     ╚═╝     ╚═╝  ╚═╝ ╚═════╝  ╚════╝ ╚══════╝ ╚═════╝   ╚═╝   ╚══════╝
// Display a listing of the resource that were created since the user's last login.
##################################################################################################################
   public function newWoodProjects(Request $request, $key=null)
   {
      // if(!checkACL('guest')) {
      //     return view('errors.403');
      // }

      //$alphas = range('A', 'Z');
      $alphas = DB::table('woodprojects')
         ->select(DB::raw('DISTINCT LEFT(name, 1) as letter'))
         ->where('created_at', '>=' , Auth::user()->last_login_date)
         //->where('user_id', '=', Auth::user()->id)
         // ->where('personal', '!=', 1)
         // ->where('published_at','!=', null)
         ->orderBy('letter')
         ->get();
      //dd($alphas);

      $letters = [];
      foreach($alphas as $alpha) {
        $letters[] = $alpha->letter;
      }

      // If $key value is passed
      if ($key) {
         $projects = WoodProject::with('category')->newWoodProjects()
            ->where('name', 'like', $key . '%')
            ->get();
         return view('backend.woodProjects.newWoodProjects', compact('projects','letters'));
      }

      $projects = WoodProject::with('category')->newWoodProjects()->get();
      return view('backend.woodProjects.newWoodProjects', compact('projects','letters'));
   }


##################################################################################################################
# ███████╗██╗  ██╗ ██████╗ ██╗    ██╗
# ██╔════╝██║  ██║██╔═══██╗██║    ██║
# ███████╗███████║██║   ██║██║ █╗ ██║
# ╚════██║██╔══██║██║   ██║██║███╗██║
# ███████║██║  ██║╚██████╔╝╚███╔███╔╝
# ╚══════╝╚═╝  ╚═╝ ╚═════╝  ╚══╝╚══╝ 
// Display the specified resource
##################################################################################################################
	public function show($id) {

		// Set the variable so we can use a button in other pages to come back to this page
		//Session::put('backURL', Route::currentRouteName());
		Session::put('fullURL', \Request::fullUrl());

		// $project = Project::with('ImageProject')->find($id);
		$project = WoodProject::find($id);
		// dd($project);

		// get previous project id
		$previous = WoodProject::where('id', '<', $project->id)->max('id');

		// get next project id
		$next = WoodProject::where('id', '>', $project->id)->min('id');
		  
		// Add 1 to views column
		DB::table('woodprojects')->where('id','=',$project->id)->increment('views',1);

		return view('woodProjects.show', compact('project','previous','next'));
	}


##################################################################################################################
# ███████╗████████╗ ██████╗ ██████╗ ███████╗
# ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
# ███████╗   ██║   ██║   ██║██████╔╝█████╗  
# ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝  
# ███████║   ██║   ╚██████╔╝██║  ██║███████╗
# ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
// Store a newly created resource in storage
##################################################################################################################
	public function store(CreateWoodProjectRequest $request) {
		
		// $this->validate($request, [
		// 	'name' => 'required',
		// 	'description' => 'required',
		// 	'category_id' => 'required',
		// 	'main_image' => 'required|image|max:1999'
		// ]);


		// Get the file object
		$file = $request->file('main_image');

		// Get file name with extension
		$filenameWithExt = $request->file('main_image')->getClientOriginalName();

		// Get just the filename
		$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);

		// Get the extension
		$extension = $request->file('main_image')->getClientOriginalExtension();

		// Create the new filename
		$filenameToStore = $filename . '_' . time() . '.' . $extension;
		//return $filenameToStore;
		
		// Check if Gallery/Images folders exists
		if (!file_exists('_woodProjects/main_images')) {
			mkdir('_woodProjects/main_images', 0777, true);
		}

		// move the file to the correct location
		$file->move('_woodProjects/main_images', $filenameToStore);
		
		// Check if Thumbs folder exists under Images
		if (!file_exists('_woodProjects/main_images/thumbs')) {
			mkdir('_woodProjects/main_images/thumbs', 0777, true);
		}

		// Create thumbnail
		$thumb = Image::make('_woodProjects/main_images/' . $filenameToStore)
			->resize(240,160)
			->save('_woodProjects/main_images/thumbs/' . $filenameToStore, 60);

		//Create album
		$project = new WoodProject;
			$project->category_id = $request->input('category_id');
			$project->name = $request->input('name');
			$project->description = $request->input('description');
			$project->main_image = $filenameToStore;
			$project->time_invested = $request->input('time_invested');
			$project->price = $request->input('price');
			$project->wood_specie_id = $request->input('wood_specie_id');
			$project->wood_type_id = $request->input('wood_type_id');
			$project->width = $request->input('width');
			$project->depth = $request->input('depth');
			$project->height = $request->input('height');
			$project->stain_type_id = $request->input('stain_type_id');
			$project->stain_color_id = $request->input('stain_color_id');
			$project->stain_sheen_id = $request->input('stain_sheen_id');
			$project->finish_type_id = $request->input('finish_type_id');
			$project->finish_sheen_id = $request->input('finish_sheen_id');
			$project->completed_at = $request->input('completed_at');
			$project->weight = $request->input('weight');
		$project->save();

		Session::flash('success','Project created.');
		return redirect()->route('woodProjects.index');
	}


##################################################################################################################
# ███████╗████████╗ ██████╗ ██████╗ ███████╗     ██████╗ ██████╗ ███╗   ███╗███╗   ███╗███████╗███╗   ██╗████████╗
# ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝    ██╔════╝██╔═══██╗████╗ ████║████╗ ████║██╔════╝████╗  ██║╚══██╔══╝
# ███████╗   ██║   ██║   ██║██████╔╝█████╗      ██║     ██║   ██║██╔████╔██║██╔████╔██║█████╗  ██╔██╗ ██║   ██║   
# ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝      ██║     ██║   ██║██║╚██╔╝██║██║╚██╔╝██║██╔══╝  ██║╚██╗██║   ██║   
# ███████║   ██║   ╚██████╔╝██║  ██║███████╗    ╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ╚═╝ ██║███████╗██║ ╚████║   ██║   
# ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝     ╚═════╝ ╚═════╝ ╚═╝     ╚═╝╚═╝     ╚═╝╚══════╝╚═╝  ╚═══╝   ╚═╝   
##################################################################################################################
	// public function storeComment(CreateCommentRequest $request, $id)
	public function storeComment(CreateCommentRequest $request, $id)
	{
		//dd($id);
		$project = woodProject::find($id);
		//dd($project);

		$comment = new Comment();
			// $comment->name = $request->name;
			// $comment->email = $request->email;
			$comment->user_id = Auth::user()->id;
			$comment->comment = $request->comment;
			$project->comments()->save($comment);
		$comment->save();

		// Save entry to log file using built-in Monolog
		// if (Auth::check()) {
		//     Log::info(Auth::user()->username . " (" . Auth::user()->id . ") commented on post (" . $post->id . ")\r\n", [json_decode($comment, true)]);
		// } else {
		//     Log::info(Request::ip() . " commented on post " . $post->id);
		// }

		Session::flash('success', 'Comment added succesfully.');
		return redirect()->route('woodProjects.show', $project->id);
	}


##################################################################################################################
# ██╗   ██╗██████╗ ██████╗  █████╗ ████████╗███████╗
# ██║   ██║██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██╔════╝
# ██║   ██║██████╔╝██║  ██║███████║   ██║   █████╗  
# ██║   ██║██╔═══╝ ██║  ██║██╔══██║   ██║   ██╔══╝  
# ╚██████╔╝██║     ██████╔╝██║  ██║   ██║   ███████╗
#  ╚═════╝ ╚═╝     ╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚══════╝
// UPDATE :: Update the specified resource in storage
##################################################################################################################
	public function update(UpdateWoodProjectRequest $request, $id)
	{
		// $this->validate($request, [
		// 	'name' => 'required',
		// 	'description' => 'required',
		// 	'category_id' => 'required',
		// 	'main_image' => 'sometimes|image|max:1999'
		// ]);

		// if(!checkACL('author')) {
		//     return view('errors.403');
		// }

		//dd($request->ref);

		if($request->file('main_image')) {
			$project = WoodProject::find($id);
			// Delete the project cover image and it's thumbnail
			unlink(public_path('_woodProjects/main_images/' . $project->main_image));
			unlink(public_path('_woodProjects/main_images/thumbs/' . $project->main_image));

			// Get the file object
			$file = $request->file('main_image');

			// Get file name with extension
			$filenameWithExt = $request->file('main_image')->getClientOriginalName();

			// Get just the filename
			$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);

			// Get the extension
			$extension = $request->file('main_image')->getClientOriginalExtension();

			// Create the new filename
			$filenameToStore = $filename . '_' . time() . '.' . $extension;
			//return $filenameToStore;
			
			// Check if Gallery/Images folders exists
			if (!file_exists('_woodProjects/main_images')) {
				mkdir('_woodProjects/main_images', 0777, true);
			}

			// move the file to the correct location
			$file->move('_woodProjects/main_images', $filenameToStore);
			
			// Check if Thumbs folder exists under Images
			if (!file_exists('_woodProjects/main_images/thumbs')) {
				mkdir('_woodProjects/main_images/thumbs', 0777, true);
			}

			// Create thumbnail
			$thumb = Image::make('_woodProjects/main_images/' . $filenameToStore)
				->resize(240,160)
				->save('_woodProjects/main_images/thumbs/' . $filenameToStore, 60);
		}

		$project = WoodProject::findOrFail($id);
			$project->category_id = $request->input('category_id');
			$project->name = $request->input('name');
			$project->description = $request->input('description');
			if ($request->file('main_image')) {
				$project->main_image = $filenameToStore;
			}
			$project->time_invested = $request->input('time_invested');
			$project->price = $request->input('price');
			$project->wood_specie_id = $request->input('wood_specie_id');
			$project->wood_type_id = $request->input('wood_type_id');
			$project->width = $request->input('width');
			$project->depth = $request->input('depth');
			$project->height = $request->input('height');
			$project->stain_type_id = $request->input('stain_type_id');
			$project->stain_color_id = $request->input('stain_color_id');
			$project->stain_sheen_id = $request->input('stain_sheen_id');
			$project->finish_type_id = $request->input('finish_type_id');
			$project->finish_sheen_id = $request->input('finish_sheen_id');
			$project->completed_at = $request->input('completed_at');
			$project->weight = $request->input('weight');
		$project->save();
		
		// Save entry to log file using built-in Monolog
		//Log::info(Auth::user()->username . " (" . Auth::user()->id . ") UPDATED article (" . $article->id . ")\r\n",
		//    [json_decode($article, true)]
		//);

		Session::flash('success','The project has been updated successfully.');
		//return redirect()->route($request->ref);
		return redirect()->route('woodProjects.index');
	}


}
<file_sep><?php

// CATEGORIES
// Route::get('category/{id}', ['uses' => 'CategoriesController@show', 'as' => 'categories.show']);

Route::group(['prefix'=>'categories'], function()
{
	Route::get('{id}/delete',						'CategoriesController@delete')					->name('delete');
	Route::get('exportPDF',							'CategoriesController@exportPDF')				->name('exportPDF');
	Route::get('import',								'CategoriesController@import')					->name('import');
	Route::get('downloadExcel/{type}',			'CategoriesController@downloadExcel')			->name('downloadExcel');
	Route::post('importExcel',						'CategoriesController@importExcel')				->name('importExport');
	Route::get('newCategories',            	'CategoriesController@newCategories')		  ->name('newCategories');
});

Route::resource('categories', 'CategoriesController');<file_sep><?php

namespace App\Http\Controllers;

use DB;
use Session;
use App\DartGame;
use App\DartScore;
use App\User;
use Illuminate\Http\Request;

class DartGamesController extends Controller
{

	 /**
	  * Display a listing of the resource.
	  *
	  * @return \Illuminate\Http\Response
	  */
	 // public function index()
	 // {
		//   $games = Dartgame::orderby('id','desc')->get();
		//   return view('darts.games.01.index', compact('games'));
	 // }

	 /**
	  * Show the form for creating a new resource.
	  *
	  * @return \Illuminate\Http\Response
	  */
	 public function create()
	 {
		  $users = User::with('profile')->where('id', '!=', 1)->orderby('username','asc')->get();
		  return view('darts.games.01.create', compact('users'));
	 }

	 /**
	  * Store a newly created resource in storage.
	  *
	  * @param  \Illuminate\Http\Request  $request
	  * @return \Illuminate\Http\Response
	  */
	 public function store(Request $request)
	 {
		  $game = new DartGame;
				$game->type = $request->type;
				$game->t1_players = $request->t1_players;
				$game->t2_players = $request->t2_players;
				$game->status = 'New';
				//dd($game);
		  $game->save();

		  Session::flash('success','The game has been created.');
		  return redirect()->route('dartgames.01.selectPlayers', $game->id);
	 }


	 public function selectPlayers($game_id)
	 {
		  // $gameID = $game_id;
		  //dd($gameID);
		  $game = DartGame::find($game_id);
		  $players = User::with('profile')->where('id', '!=', 1)->orderby('username', 'asc')->get();
		  return view('darts.games.01.selectPlayers', compact('players','game'));
	 }


	 public function storePlayers(Request $request)
	 {
		  //dd($request);
		  $game = DartGame::find($request->game_id);
		  //dd($game);
		  if (isset($request->team1players))
		  {
				foreach($request->team1players as $player)
				{
					 DB::insert('insert into dartgame_user (dartgame_id, team_id, user_id) values (?, ?, ?)', [$game->id, 1, $player]);
				}
		  }

		  if (isset($request->team2players))
		  {
				foreach($request->team2players as $player)
				{
					 DB::insert('insert into dartgame_user (dartgame_id, team_id, user_id) values (?, ?, ?)', [$game->id, 2, $player]);
				}
		  }

		  Session::flash('success','The game has been created.');
		  return redirect()->route('dartgames.01.index');

	 }


	 /**
	  * Display the specified resource.
	  *
	  * @param  int  $id
	  * @return \Illuminate\Http\Response
	  */
	 public function show($id)
	 {
		  //
	 }

	 /**
	  * Show the form for editing the specified resource.
	  *
	  * @param  int  $id
	  * @return \Illuminate\Http\Response
	  */
	 public function edit($id)
	 {
		  //
	 }

	 /**
	  * Update the specified resource in storage.
	  *
	  * @param  \Illuminate\Http\Request  $request
	  * @param  int  $id
	  * @return \Illuminate\Http\Response
	  */
	 public function update(Request $request, $id)
	 {
		  //
	 }

	 /**
	  * Remove the specified resource from storage.
	  *
	  * @param  int  $id
	  * @return \Illuminate\Http\Response
	  */
	 public function destroy($id)
	 {
		// if(!checkACL('manager')) {
		//   return view('errors.403');
		// }

		$game = DartGame::find($id);
		$game->delete();

		// Save entry to log file using built-in Monolog
		//Log::info(Auth::user()->username . " (" . Auth::user()->id . ") DELETED category (" . $category->id . ")\r\n", [$category = json_decode($category, true)]);

		Session::flash('success', 'The game and related entries were successfully deleted!');
		return redirect()->route('dartgames.01.index');
	 }
}
<file_sep><?php

namespace App\Http\Controllers\Backend;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use Illuminate\Support\Facades\Input;
use App\Category;
use App\Module;
use App\Recipe;
use App\User;
use Carbon\Carbon;
use Auth;
use DB;
use Excel;
use File;
use Image;
use JavaScript;
use Log;
use PDF;
use Purifier;
use Session;
use Storage;
use Table;
use URL;

use App\Http\Requests\CreateRecipeRequest;
use App\Http\Requests\UpdateRecipeRequest;

class RecipesController extends Controller
{

##################################################################################################################
#  ██████╗ ██████╗ ███╗   ██╗███████╗████████╗██████╗ ██╗   ██╗ ██████╗████████╗
# ██╔════╝██╔═══██╗████╗  ██║██╔════╝╚══██╔══╝██╔══██╗██║   ██║██╔════╝╚══██╔══╝
# ██║     ██║   ██║██╔██╗ ██║███████╗   ██║   ██████╔╝██║   ██║██║        ██║   
# ██║     ██║   ██║██║╚██╗██║╚════██║   ██║   ██╔══██╗██║   ██║██║        ██║   
# ╚██████╗╚██████╔╝██║ ╚████║███████║   ██║   ██║  ██║╚██████╔╝╚██████╗   ██║   
#  ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝  ╚═════╝   ╚═╝   
##################################################################################################################
   public function __construct() {
      // only allow authenticated users to access these pages
      //$this->middleware('auth', ['except'=>['index','show']]);
      // changing auth to guest would only allow guests to access these pages
      // you can also restrict the actions by adding ['except' => 'name_of_action'] at the end
      $this->middleware('auth');

      //Log::useFiles(storage_path().'/logs/articles.log');
      //Log::useFiles(storage_path().'/logs/audits.log');
   }


##################################################################################################################
#  █████╗ ██████╗ ██████╗     ███████╗ █████╗ ██╗   ██╗ ██████╗ ██████╗ ██╗████████╗███████╗
# ██╔══██╗██╔══██╗██╔══██╗    ██╔════╝██╔══██╗██║   ██║██╔═══██╗██╔══██╗██║╚══██╔══╝██╔════╝
# ███████║██║  ██║██║  ██║    █████╗  ███████║██║   ██║██║   ██║██████╔╝██║   ██║   █████╗  
# ██╔══██║██║  ██║██║  ██║    ██╔══╝  ██╔══██║╚██╗ ██╔╝██║   ██║██╔══██╗██║   ██║   ██╔══╝  
# ██║  ██║██████╔╝██████╔╝    ██║     ██║  ██║ ╚████╔╝ ╚██████╔╝██║  ██║██║   ██║   ███████╗
# ╚═╝  ╚═╝╚═════╝ ╚═════╝     ╚═╝     ╚═╝  ╚═╝  ╚═══╝   ╚═════╝ ╚═╝  ╚═╝╚═╝   ╚═╝   ╚══════╝
##################################################################################################################
   public function addfavorite($id)
   {
      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();
      //dd($ref);

      $user = Auth::user()->id;
      $recipe = Recipe::find($id);

      $recipe->favorites()->sync([$user], false);

      Session::flash ('success','The recipe was successfully added to your Favorites list!');
      // return redirect()->route('backend.articles.index');
      //return redirect()->route($ref, ['id'=>$id]);
      //return redirect()->route('profile', ['id' => 1]);
      return redirect()->back();
   }


##################################################################################################################
#  ██████╗██████╗ ███████╗ █████╗ ████████╗███████╗
# ██╔════╝██╔══██╗██╔════╝██╔══██╗╚══██╔══╝██╔════╝
# ██║     ██████╔╝█████╗  ███████║   ██║   █████╗  
# ██║     ██╔══██╗██╔══╝  ██╔══██║   ██║   ██╔══╝  
# ╚██████╗██║  ██║███████╗██║  ██║   ██║   ███████╗
#  ╚═════╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝   ╚═╝   ╚══════╝
// Show the form for creating a new resource
##################################################################################################################
   public function create()
   {
      // if(!checkACL('author')) {
      //     return view('errors.403');
      // }

      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      // find all categories in the categories table and pass them to the view
      $categories = Category::whereHas('module', function ($query) {
         $query->where('name', '=', 'recipes');
      })->orderBy('name','asc')->get();

      // Create an empty array to store the categories
      $cats = [];

      // Store the category values into the $cats array
      foreach ($categories as $category) {
         $cats[$category->id] = $category->name;
      }

      return view('backend.recipes.create')->withCategories($cats)->withRef($ref);
   }

##################################################################################################################
# ██████╗ ███████╗██╗     ███████╗████████╗███████╗     █████╗ ██╗     ██╗     
# ██╔══██╗██╔════╝██║     ██╔════╝╚══██╔══╝██╔════╝    ██╔══██╗██║     ██║     
# ██║  ██║█████╗  ██║     █████╗     ██║   █████╗      ███████║██║     ██║     
# ██║  ██║██╔══╝  ██║     ██╔══╝     ██║   ██╔══╝      ██╔══██║██║     ██║     
# ██████╔╝███████╗███████╗███████╗   ██║   ███████╗    ██║  ██║███████╗███████╗
# ╚═════╝ ╚══════╝╚══════╝╚══════╝   ╚═╝   ╚══════╝    ╚═╝  ╚═╝╚══════╝╚══════╝
// Mass Delete selected rows - all selected records
##################################################################################################################
   public function deleteAll(Request $request)
   {
      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      //dd('TEST_DELETE');
      $this->validate($request, [
         'checked' => 'required',
      ]);
      //dd('TEST_DELETE');

      $checked = $request->input('checked');
      //dd($checked);

      // $article = Article::withTrashed()->findOrFail($checked);
      //Article::destroy($checked);
      Recipe::whereIn('id', $checked)->forceDelete();

      Session::flash('success','The recipes were deleted successfully.');
      return redirect()->route($ref);
   }


##################################################################################################################
# ██████╗ ███████╗██╗     ███████╗████████╗███████╗    ████████╗██████╗  █████╗ ███████╗██╗  ██╗███████╗██████╗ 
# ██╔══██╗██╔════╝██║     ██╔════╝╚══██╔══╝██╔════╝    ╚══██╔══╝██╔══██╗██╔══██╗██╔════╝██║  ██║██╔════╝██╔══██╗
# ██║  ██║█████╗  ██║     █████╗     ██║   █████╗         ██║   ██████╔╝███████║███████╗███████║█████╗  ██║  ██║
# ██║  ██║██╔══╝  ██║     ██╔══╝     ██║   ██╔══╝         ██║   ██╔══██╗██╔══██║╚════██║██╔══██║██╔══╝  ██║  ██║
# ██████╔╝███████╗███████╗███████╗   ██║   ███████╗       ██║   ██║  ██║██║  ██║███████║██║  ██║███████╗██████╔╝
# ╚═════╝ ╚══════╝╚══════╝╚══════╝   ╚═╝   ╚══════╝       ╚═╝   ╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝╚══════╝╚═════╝ 
// Permanently remove the specified resource from storage - individual record
##################################################################################################################
   public static function deleteTrashed($id)
   {
      // if(!checkACL('manager')) {
         // return view('errors.403');
      // }
      //dd($id);
      $recipe = Recipe::withTrashed()->findOrFail($id);
      $recipe->forceDelete();

      Session::flash ('success','The recipe was deleted successfully.');
      return redirect()->route('backend.recipes.trashed');
   }


##################################################################################################################
# ██████╗ ███████╗███████╗████████╗██████╗  ██████╗ ██╗   ██╗
# ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔══██╗██╔═══██╗╚██╗ ██╔╝
# ██║  ██║█████╗  ███████╗   ██║   ██████╔╝██║   ██║ ╚████╔╝ 
# ██║  ██║██╔══╝  ╚════██║   ██║   ██╔══██╗██║   ██║  ╚██╔╝  
# ██████╔╝███████╗███████║   ██║   ██║  ██║╚██████╔╝   ██║   
# ╚═════╝ ╚══════╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝    ╚═╝   
// Remove the specified resource from storage
// Used in the index page and trashAll action to soft delete multiple records
##################################################################################################################
   public function destroy($id)
   {
      // if(!checkACL('author')) {
      //     return view('errors.403');
      // }

      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      $recipe = Recipe::findOrFail($id);
         $recipe->published_at = Null;
            // Delete related favorites
            $favorites = DB::select('select * from recipe_user where recipe_id = '. $id, [1]);
              foreach($favorites as $favorite) {
               $recipe->favoriteRecipes()->detach($favorite);
              }
         $recipe->save();
      $recipe->delete();

      // Save entry to log file using built-in Monolog
      //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") DELETED article (" . $article->id . ")\r\n",
      //    [json_decode($article, true)]
      //);

      Session::flash('success','The recipe was trashed successfully.');
      return redirect()->route($ref);
   }


##################################################################################################################
# ██████╗  ██████╗ ██╗    ██╗███╗   ██╗██╗      ██████╗  █████╗ ██████╗     ███████╗██╗  ██╗ ██████╗███████╗██╗     
# ██╔══██╗██╔═══██╗██║    ██║████╗  ██║██║     ██╔═══██╗██╔══██╗██╔══██╗    ██╔════╝╚██╗██╔╝██╔════╝██╔════╝██║     
# ██║  ██║██║   ██║██║ █╗ ██║██╔██╗ ██║██║     ██║   ██║███████║██║  ██║    █████╗   ╚███╔╝ ██║     █████╗  ██║     
# ██║  ██║██║   ██║██║███╗██║██║╚██╗██║██║     ██║   ██║██╔══██║██║  ██║    ██╔══╝   ██╔██╗ ██║     ██╔══╝  ██║     
# ██████╔╝╚██████╔╝╚███╔███╔╝██║ ╚████║███████╗╚██████╔╝██║  ██║██████╔╝    ███████╗██╔╝ ██╗╚██████╗███████╗███████╗
# ╚═════╝  ╚═════╝  ╚══╝╚══╝ ╚═╝  ╚═══╝╚══════╝ ╚═════╝ ╚═╝  ╚═╝╚═════╝     ╚══════╝╚═╝  ╚═╝ ╚═════╝╚══════╝╚══════╝
##################################################################################################################
   public function downloadExcel($type)
   {
      // if(!checkACL('manager')) {
      //   // Save entry to log file of failure
      //   Log::warning(Auth::user()->username . " (" . Auth::user()->id . ") tried to access :: Articles / Download");
      //   return view('errors.403');
      // }

      $referrer = request()->headers->get('referer');
      //dd($referrer);
      if ($referrer == 'http://localhost:8000/backend/recipes/myRecipes') {
         $data = Recipe::myRecipes()->get()->toArray();
      // } elseif ($referrer == 'http://localhost:8000/backend/articles'){
      //     $data = Article::get()->toArray();
      } else {
         $data = Recipe::get()->toArray();
      }

      // Save entry to log file of failure
      //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") downloaded :: articles");

      return Excel::create('Recipes_List', function($excel) use ($data) {
         $excel->sheet('mySheet', function($sheet) use ($data)
         {
            $sheet->fromArray($data);
         });
      })->download($type);
   }


##################################################################################################################
# ██████╗ ██╗   ██╗██████╗ ██╗     ██╗ ██████╗ █████╗ ████████╗███████╗
# ██╔══██╗██║   ██║██╔══██╗██║     ██║██╔════╝██╔══██╗╚══██╔══╝██╔════╝
# ██║  ██║██║   ██║██████╔╝██║     ██║██║     ███████║   ██║   █████╗  
# ██║  ██║██║   ██║██╔═══╝ ██║     ██║██║     ██╔══██║   ██║   ██╔══╝  
# ██████╔╝╚██████╔╝██║     ███████╗██║╚██████╗██║  ██║   ██║   ███████╗
# ╚═════╝  ╚═════╝ ╚═╝     ╚══════╝╚═╝ ╚═════╝╚═╝  ╚═╝   ╚═╝   ╚══════╝
// DUPLICATE :: Duplicate the specified resource in storage.
##################################################################################################################
   public function duplicate($id)
   {
      //if(!checkACL('manager')) {
      //  // Save entry to log file of failure
      //  Log::warning(Auth::user()->username . " (" . Auth::user()->id . ") tried to access :: Articles / Duplicate");
      //  return view('errors.403');
      //}

      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      $recipe = Recipe::find($id);
        $newRecipe = $recipe->replicate();
        $newRecipe->user_id = Auth::user()->id;
      $newRecipe->save();

      // change the user_id field to be that of the user that is currently logged in
      
      //$newArticle->views = 0;
      //$newArticle->save();

      // Save entry to log file using built-in Monolog
      //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") duplicated :: article " . $article->id . " to article ". $newArticle->id);

      Session::flash ('success','The recipe was duplicated successfully!');
      return redirect()->route($ref);
   }


##################################################################################################################
# ███████╗██████╗ ██╗████████╗
# ██╔════╝██╔══██╗██║╚══██╔══╝
# █████╗  ██║  ██║██║   ██║   
# ██╔══╝  ██║  ██║██║   ██║   
# ███████╗██████╔╝██║   ██║   
# ╚══════╝╚═════╝ ╚═╝   ╚═╝   
// Show the form for editing the specified resource
##################################################################################################################
   public function edit($id)
   {
      // if(!checkACL('author')) {
      //     return view('errors.403');
      // }

      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      // Find the article to edit
      $recipe = Recipe::findOrFail($id);

      // find all categories in the categories table and pass them to the view
      $categories = Category::whereHas('module', function ($query) {
         $query->where('name', '=', 'recipes');
      })->get();

      // Create an empty array to store the categories
      $cats = [];
      // Store the category values into the $cats array
      foreach ($categories as $category) {
         $cats[$category->id] = $category->name;
      }

      return view('backend.recipes.edit', compact('recipe'))->withCategories($cats)->withRef($ref);
   }


##################################################################################################################
# ███████╗██╗   ██╗████████╗██╗   ██╗██████╗ ███████╗
# ██╔════╝██║   ██║╚══██╔══╝██║   ██║██╔══██╗██╔════╝
# █████╗  ██║   ██║   ██║   ██║   ██║██████╔╝█████╗  
# ██╔══╝  ██║   ██║   ██║   ██║   ██║██╔══██╗██╔══╝  
# ██║     ╚██████╔╝   ██║   ╚██████╔╝██║  ██║███████╗
# ╚═╝      ╚═════╝    ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
// Display a list of resources that will be published at a later date
##################################################################################################################
   public function future(Request $request, $key=null)
   {
      // if(!checkACL('guest')) {
      //     return view('errors.403');
      // }

      //$alphas = range('A', 'Z');
      $alphas = DB::table('recipes')
         ->select(DB::raw('DISTINCT LEFT(title, 1) as letter'))
         // ->where('personal', '!=', 1)
         ->where('published_at','>', Carbon::Now())
         ->orderBy('letter')
         ->get();
         //dd($alphas);

      $letters = [];
      foreach($alphas as $alpha) {
         $letters[] = $alpha->letter;
      }

      // If $key value is passed
      if ($key) {
         $recipes = Recipe::with('user','category')->future()
            ->where('title', 'like', $key . '%')
            ->orderBy('title', 'asc')
            ->get();
         return view('backend.recipes.future', compact('recipes','letters'));
      }

      // No $key value is passed
      $recipes = Recipe::with('user','category')->future()->get();
      return view('backend.recipes.future', compact('recipes','letters'));
   }


##################################################################################################################
# ██╗███╗   ██╗██████╗ ███████╗██╗  ██╗
# ██║████╗  ██║██╔══██╗██╔════╝╚██╗██╔╝
# ██║██╔██╗ ██║██║  ██║█████╗   ╚███╔╝ 
# ██║██║╚██╗██║██║  ██║██╔══╝   ██╔██╗ 
# ██║██║ ╚████║██████╔╝███████╗██╔╝ ██╗
# ╚═╝╚═╝  ╚═══╝╚═════╝ ╚══════╝╚═╝  ╚═╝
// Display a list of resources
##################################################################################################################
   public function index() {
      return view('backend.recipes.index');
   }


##################################################################################################################
# ██╗███╗   ███╗██████╗  ██████╗ ██████╗ ████████╗
# ██║████╗ ████║██╔══██╗██╔═══██╗██╔══██╗╚══██╔══╝
# ██║██╔████╔██║██████╔╝██║   ██║██████╔╝   ██║   
# ██║██║╚██╔╝██║██╔═══╝ ██║   ██║██╔══██╗   ██║   
# ██║██║ ╚═╝ ██║██║     ╚██████╔╝██║  ██║   ██║   
# ╚═╝╚═╝     ╚═╝╚═╝      ╚═════╝ ╚═╝  ╚═╝   ╚═╝   
// IMPORT :: Show the form for importing entries to storage.
##################################################################################################################
   public function import()
   {
      // if(!checkACL('manager')) {
      //   // Save entry to log file of failure
      //   Log::warning(Auth::user()->username . " (" . Auth::user()->id . ") tried to access :: Articles / Import");
      //   return view('errors.403');
      // }

      // Save entry to log file of failure
      //Log::warning(Auth::user()->username . " (" . Auth::user()->id . ") accessed :: Articles / Import");

      return view('backend.recipes.import');
   }


##################################################################################################################
# ██╗███╗   ███╗██████╗  ██████╗ ██████╗ ████████╗    ███████╗██╗   ██╗███╗   ██╗ ██████╗████████╗██╗ ██████╗ ███╗   ██╗
# ██║████╗ ████║██╔══██╗██╔═══██╗██╔══██╗╚══██╔══╝    ██╔════╝██║   ██║████╗  ██║██╔════╝╚══██╔══╝██║██╔═══██╗████╗  ██║
# ██║██╔████╔██║██████╔╝██║   ██║██████╔╝   ██║       █████╗  ██║   ██║██╔██╗ ██║██║        ██║   ██║██║   ██║██╔██╗ ██║
# ██║██║╚██╔╝██║██╔═══╝ ██║   ██║██╔══██╗   ██║       ██╔══╝  ██║   ██║██║╚██╗██║██║        ██║   ██║██║   ██║██║╚██╗██║
# ██║██║ ╚═╝ ██║██║     ╚██████╔╝██║  ██║   ██║       ██║     ╚██████╔╝██║ ╚████║╚██████╗   ██║   ██║╚██████╔╝██║ ╚████║
# ╚═╝╚═╝     ╚═╝╚═╝      ╚═════╝ ╚═╝  ╚═╝   ╚═╝       ╚═╝      ╚═════╝ ╚═╝  ╚═══╝ ╚═════╝   ╚═╝   ╚═╝ ╚═════╝ ╚═╝  ╚═══╝
##################################################################################################################
   public function importExcel()
   {
      // if(!checkACL('manager')) {
      //   // Save entry to log file of failure
      //   Log::warning(Auth::user()->username . " (" . Auth::user()->id . ") tried to access :: Admin / Articles / Import");
      //   return view('errors.403');
      // }

      if(Input::hasFile('import_file')) {
            $path = Input::file('import_file')->getRealPath();
            $data = Excel::load($path, function($reader) {
         })->get();

         if(!empty($data) && $data->count()) {
            foreach ($data as $key => $value) {
               $insert[] = [
                  'user_id'            => $value->user_id,
                  'category_id'        => $value->category_id,
                  'title'              => $value->title,            
                  'description_eng'    => $value->description_eng,
                  'description_fre'    => $value->description_fre,
                  'views'              =>  0,
                  'deleted_at'         => $value->deleted_at,
                  'published_at'       => $value->published_at,
                  'created_at'         => $value->created_at,
                  'updated_at'         => $value->updated_at,
               ];
            }

            if(!empty($insert)) {
               DB::table('articles')->insert($insert);

               // Save entry to log file of failure
               //Log::warning(Auth::user()->username . " (" . Auth::user()->id . ") imported :: articles");

               Session::flash('success', $data->count() . ' articles imported successfully!');
               return redirect()->route('backend.articles.index');
            }
         }
      }
      return back();
   }


##################################################################################################################
# ███╗   ███╗ █████╗ ██╗  ██╗███████╗    ██████╗ ██████╗ ██╗██╗   ██╗ █████╗ ████████╗███████╗
# ████╗ ████║██╔══██╗██║ ██╔╝██╔════╝    ██╔══██╗██╔══██╗██║██║   ██║██╔══██╗╚══██╔══╝██╔════╝
# ██╔████╔██║███████║█████╔╝ █████╗      ██████╔╝██████╔╝██║██║   ██║███████║   ██║   █████╗  
# ██║╚██╔╝██║██╔══██║██╔═██╗ ██╔══╝      ██╔═══╝ ██╔══██╗██║╚██╗ ██╔╝██╔══██║   ██║   ██╔══╝  
# ██║ ╚═╝ ██║██║  ██║██║  ██╗███████╗    ██║     ██║  ██║██║ ╚████╔╝ ██║  ██║   ██║   ███████╗
# ╚═╝     ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝    ╚═╝     ╚═╝  ╚═╝╚═╝  ╚═══╝  ╚═╝  ╚═╝   ╚═╝   ╚══════╝
##################################################################################################################
   public function makeprivate($id)
   {
      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      $article = Article::find($id);
         $article->personal = 1;
      $article->save();

      // Save entry to log file using built-in Monolog
      //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") MADE recipe (" . $recipe->id . ") PRIVATE \r\n", [json_decode($recipe, true)]);

      Session::flash('success','The article was made private successfully');
      return redirect()->route($ref);
   }


##################################################################################################################
# ███╗   ███╗██╗   ██╗    ███████╗ █████╗ ██╗   ██╗ ██████╗ ██████╗ ██╗████████╗███████╗███████╗
# ████╗ ████║╚██╗ ██╔╝    ██╔════╝██╔══██╗██║   ██║██╔═══██╗██╔══██╗██║╚══██╔══╝██╔════╝██╔════╝
# ██╔████╔██║ ╚████╔╝     █████╗  ███████║██║   ██║██║   ██║██████╔╝██║   ██║   █████╗  ███████╗
# ██║╚██╔╝██║  ╚██╔╝      ██╔══╝  ██╔══██║╚██╗ ██╔╝██║   ██║██╔══██╗██║   ██║   ██╔══╝  ╚════██║
# ██║ ╚═╝ ██║   ██║       ██║     ██║  ██║ ╚████╔╝ ╚██████╔╝██║  ██║██║   ██║   ███████╗███████║
# ╚═╝     ╚═╝   ╚═╝       ╚═╝     ╚═╝  ╚═╝  ╚═══╝   ╚═════╝ ╚═╝  ╚═╝╚═╝   ╚═╝   ╚══════╝╚══════╝
// MY FAVORITES :: Display a listing of the resource that have been favorited by a specific user.
##################################################################################################################
   public function myFavorites()
   {
      if(!checkACL('user')) {
         return view('errors.backend.403');
      }
      // $alphas = DB::table('recipes')
      //   ->select(DB::raw('DISTINCT LEFT(title, 1) as letter'))
      //   //->where('user_id','=',Auth::user()->id)
      //   ->where('user_id','=',-1)
      //   ->orderBy('letter')
      //   ->get();
      // //dd($alphas);

      //$letters = [];
      //   foreach($alphas as $alpha) {
      //     $letters[] = $alpha->letter;
      //   }
      // //dd($letters);

      // find the favorites
      $favs = DB::table('recipe_user')->where('user_id','=',Auth::user()->id)->get();
      //dd($favs);
      //$favs = Recipe::with('user','category')->where('recipe_user.user_id','=',Auth::user()->id)->get();
      //$recipes = Recipe::with('user','category')->where('user_id','=', Auth::user()->id)->orderBy('title', 'asc')->get();

      // // Create an empty array to store the recipes        
      $recipes = [];

      // // Store the recipe values into the $recipes array
      foreach ($favs as $fav)
      {
        $recipes[$fav->id] = Recipe::with('user','category')->find($fav->recipe_id);
      }
      //dd($recipes);
      // // Sort the recipes array by title
      $recipes = array_values(array_sort($recipes, function ($value) {
         return $value['id'];
      }));
      //dd($recipes);
      // return view('recipes.viewfavorites')->withRecipes($recipes);
      //return view('recipes.myFavorites', compact('recipes','letters'));
      //return view('recipes.index', compact('recipes','letters'));
      return view('backend.recipes.myFavorites', compact('recipes'));
   }


##################################################################################################################
# ███╗   ███╗██╗   ██╗    ██████╗ ███████╗ ██████╗██╗██████╗ ███████╗███████╗
# ████╗ ████║╚██╗ ██╔╝    ██╔══██╗██╔════╝██╔════╝██║██╔══██╗██╔════╝██╔════╝
# ██╔████╔██║ ╚████╔╝     ██████╔╝█████╗  ██║     ██║██████╔╝█████╗  ███████╗
# ██║╚██╔╝██║  ╚██╔╝      ██╔══██╗██╔══╝  ██║     ██║██╔═══╝ ██╔══╝  ╚════██║
# ██║ ╚═╝ ██║   ██║       ██║  ██║███████╗╚██████╗██║██║     ███████╗███████║
# ╚═╝     ╚═╝   ╚═╝       ╚═╝  ╚═╝╚══════╝ ╚═════╝╚═╝╚═╝     ╚══════╝╚══════╝
// Display a listing of the resource that belong to a specific user.
##################################################################################################################

   public function myRecipes(Request $request, $key=null)
   {
      if(!checkACL('author')) {
          return view('errors.backend.403');
      }

      //$alphas = range('A', 'Z');
      $alphas = DB::table('recipes')
         ->select(DB::raw('DISTINCT LEFT(title, 1) as letter'))
         ->where('user_id', '=', Auth::user()->id)
         // ->where('personal', '!=', 1)
         // ->where('published_at','!=', null)
         ->orderBy('letter')
         ->get();
      //dd($alphas);

      $letters = [];
      foreach($alphas as $alpha) {
        $letters[] = $alpha->letter;
      }

      // If $key value is passed
      if ($key) {
         $recipes = Recipe::with('user','category')->myRecipes()
            ->where('title', 'like', $key . '%')
            ->get();
         return view('backend.recipes.myRecipes', compact('recipes','letters'));
      }

      $recipes = Recipe::with('user','category')->myRecipes()->get();
      return view('backend.recipes.myRecipes', compact('recipes','letters'));
   }


##################################################################################################################
# ███╗   ██╗███████╗██╗    ██╗    ██████╗ ███████╗ ██████╗██╗██████╗ ███████╗███████╗
# ████╗  ██║██╔════╝██║    ██║    ██╔══██╗██╔════╝██╔════╝██║██╔══██╗██╔════╝██╔════╝
# ██╔██╗ ██║█████╗  ██║ █╗ ██║    ██████╔╝█████╗  ██║     ██║██████╔╝█████╗  ███████╗
# ██║╚██╗██║██╔══╝  ██║███╗██║    ██╔══██╗██╔══╝  ██║     ██║██╔═══╝ ██╔══╝  ╚════██║
# ██║ ╚████║███████╗╚███╔███╔╝    ██║  ██║███████╗╚██████╗██║██║     ███████╗███████║
# ╚═╝  ╚═══╝╚══════╝ ╚══╝╚══╝     ╚═╝  ╚═╝╚══════╝ ╚═════╝╚═╝╚═╝     ╚══════╝╚══════╝
// Display a listing of the resource that were created since the user's last login.
##################################################################################################################
   public function newRecipes(Request $request, $key=null)
   {
      if(!checkACL('author')) {
          return view('errors.backend.403');
      }

      //$alphas = range('A', 'Z');
      $alphas = DB::table('recipes')
         ->select(DB::raw('DISTINCT LEFT(title, 1) as letter'))
         ->where('created_at', '>=' , Auth::user()->last_login_date)
         //->where('user_id', '=', Auth::user()->id)
         // ->where('personal', '!=', 1)
         // ->where('published_at','!=', null)
         ->orderBy('letter')
         ->get();
      //dd($alphas);

      $letters = [];
      foreach($alphas as $alpha) {
        $letters[] = $alpha->letter;
      }

      // If $key value is passed
      if ($key) {
         $recipes = Recipe::with('user','category')->newRecipes()
            ->where('title', 'like', $key . '%')
            ->get();
         return view('backend.recipes.newRecipes', compact('recipes','letters'));
      }

      $recipes = Recipe::with('user','category')->newRecipes()->get();
      return view('backend.recipes.newRecipes', compact('recipes','letters'));
   }


##################################################################################################################
# ██████╗ ██████╗ ███████╗    ██╗   ██╗██╗███████╗██╗    ██╗
# ██╔══██╗██╔══██╗██╔════╝    ██║   ██║██║██╔════╝██║    ██║
# ██████╔╝██║  ██║█████╗      ██║   ██║██║█████╗  ██║ █╗ ██║
# ██╔═══╝ ██║  ██║██╔══╝      ╚██╗ ██╔╝██║██╔══╝  ██║███╗██║
# ██║     ██████╔╝██║          ╚████╔╝ ██║███████╗╚███╔███╔╝
# ╚═╝     ╚═════╝ ╚═╝           ╚═══╝  ╚═╝╚══════╝ ╚══╝╚══╝ 
// 
##################################################################################################################
   // public function exportPDF()
   // {
   //   // if(!checkACL('manager')) {
   //   //   return view('errors.403');
   //   // }

   //   $data = Article::get()->toArray();
   //   return Excel::create('Articles_List', function($excel) use ($data) {
   //     $excel->sheet('mySheet', function($sheet) use ($data)
   //     {
   //       $sheet->fromArray($data);
   //     });
   //   })->download("pdf");
   // }

   // public function downloadPDF()
   // {
   //   $pdf = PDF::loadView('backend.articles.pdfView');
   //   return $pdf->download('articles.pdf');
   // }

   public function pdfview(Request $request)
   {
      //$articles = DB::table("articles")->get();

      $referrer = request()->headers->get('referer');
      if ($referrer == 'http://localhost:8000/backend/recipes/myRecipes') {
         $data = Recipe::myRecipes()->get();
      } else {
         $data = Recipe::All();
      }

      view()->share('recipes',$data);

      if($request->has('download')){
         $pdf = PDF::loadView('backend.recipes.pdfDownload');
         //$pdf->setPaper('A4', 'landscape');
         return $pdf->download('recipes.pdf');
      }

      return view('backend.recipes.pdfPreview');
   }


##################################################################################################################
# ██████╗ ██████╗ ██╗███╗   ██╗████████╗
# ██╔══██╗██╔══██╗██║████╗  ██║╚══██╔══╝
# ██████╔╝██████╔╝██║██╔██╗ ██║   ██║   
# ██╔═══╝ ██╔══██╗██║██║╚██╗██║   ██║   
# ██║     ██║  ██║██║██║ ╚████║   ██║   
# ╚═╝     ╚═╝  ╚═╝╚═╝╚═╝  ╚═══╝   ╚═╝   
##################################################################################################################
   public function print($id)
   {
      // if(!checkACL('author')) {
      //     return view('errors.403');
      // }

      $recipe = Recipe::find($id);

      // Save entry to log file using built-in Monolog
      // Log::info(Auth::user()->username . " (" . Auth::user()->id . ") PRINTED article (" . $article->id . ")\r\n", 
      //     [json_decode($article, true)]
      // );

      return view('backend.recipes.print')->withRecipe($recipe);
   }


##################################################################################################################
# ██████╗ ██╗   ██╗██████╗ ██╗     ██╗███████╗██╗  ██╗
# ██╔══██╗██║   ██║██╔══██╗██║     ██║██╔════╝██║  ██║
# ██████╔╝██║   ██║██████╔╝██║     ██║███████╗███████║
# ██╔═══╝ ██║   ██║██╔══██╗██║     ██║╚════██║██╔══██║
# ██║     ╚██████╔╝██████╔╝███████╗██║███████║██║  ██║
# ╚═╝      ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚══════╝╚═╝  ╚═╝
##################################################################################################################
   public function publish($id)
   {
      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      $recipe = Recipe::find($id);
        $recipe->published_at = Carbon::now();
        $recipe->deleted_at = Null;
      $recipe->save();

      Session::flash ('success','The recipe was successfully published.');
      return redirect()->route($ref);
   }


##################################################################################################################
# ██████╗ ██╗   ██╗██████╗ ██╗     ██╗███████╗██╗  ██╗     █████╗ ██╗     ██╗     
# ██╔══██╗██║   ██║██╔══██╗██║     ██║██╔════╝██║  ██║    ██╔══██╗██║     ██║     
# ██████╔╝██║   ██║██████╔╝██║     ██║███████╗███████║    ███████║██║     ██║     
# ██╔═══╝ ██║   ██║██╔══██╗██║     ██║╚════██║██╔══██║    ██╔══██║██║     ██║     
# ██║     ╚██████╔╝██████╔╝███████╗██║███████║██║  ██║    ██║  ██║███████╗███████╗
# ╚═╝      ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚══════╝╚═╝  ╚═╝    ╚═╝  ╚═╝╚══════╝╚══════╝
##################################################################################################################
   public function publishAll(Request $request)
   {
      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      //dd('TEST_DELETE');
      $this->validate($request, [
         'checked' => 'required',
      ]);
      //dd('TEST_DELETE');

      $checked = $request->input('checked');
      //dd($checked);

      // $article = Article::withTrashed()->findOrFail($checked);
      //Article::destroy($checked);
      //Article::whereIn('id', $checked)->publish();
      foreach ($checked as $item) {
         //dd($item);
         $recipe = Recipe::withTrashed()->find($item);
         //dd($article);
            $recipe->published_at = Carbon::now();
            $recipe->deleted_at = Null;
         $recipe->save();
      }

      Session::flash('success','The recipes were published successfully.');
      return redirect()->route($ref);
   }


##################################################################################################################
# ██████╗ ██╗   ██╗██████╗ ██╗     ██╗███████╗██╗  ██╗███████╗██████╗ 
# ██╔══██╗██║   ██║██╔══██╗██║     ██║██╔════╝██║  ██║██╔════╝██╔══██╗
# ██████╔╝██║   ██║██████╔╝██║     ██║███████╗███████║█████╗  ██║  ██║
# ██╔═══╝ ██║   ██║██╔══██╗██║     ██║╚════██║██╔══██║██╔══╝  ██║  ██║
# ██║     ╚██████╔╝██████╔╝███████╗██║███████║██║  ██║███████╗██████╔╝
# ╚═╝      ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚══════╝╚═╝  ╚═╝╚══════╝╚═════╝ 
##################################################################################################################
   public function published(Request $request, $key=null)
   {
      if(!checkACL('user')) {
          return view('errors.backend.403');
      }

      //$alphas = range('A', 'Z');
        $alphas = DB::table('recipes')
         ->select(DB::raw('DISTINCT LEFT(title, 1) as letter'))
         ->where('published_at','<', Carbon::Now())
         ->where('deleted_at','=', Null)
         ->orderBy('letter')
         ->get();

      $letters = [];
      foreach($alphas as $alpha) {
        $letters[] = $alpha->letter;
      }

      // If $key value is passed
      if ($key) {
         $recipes = Recipe::with('user','category')->published()
            ->where('title', 'like', $key . '%')
            ->orderBy('title', 'asc')
            ->get();
         return view('backend.recipes.published', compact('recipes','letters'));
      }

      // No $key value is passed
      $recipes = Recipe::with('user','category')->published()->get();
      return view('backend.recipes.published', compact('recipes','letters'));
   }


##################################################################################################################
# ██████╗ ███████╗███╗   ███╗ ██████╗ ██╗   ██╗███████╗    ███████╗ █████╗ ██╗   ██╗ ██████╗ ██████╗ ██╗████████╗███████╗
# ██╔══██╗██╔════╝████╗ ████║██╔═══██╗██║   ██║██╔════╝    ██╔════╝██╔══██╗██║   ██║██╔═══██╗██╔══██╗██║╚══██╔══╝██╔════╝
# ██████╔╝█████╗  ██╔████╔██║██║   ██║██║   ██║█████╗      █████╗  ███████║██║   ██║██║   ██║██████╔╝██║   ██║   █████╗  
# ██╔══██╗██╔══╝  ██║╚██╔╝██║██║   ██║╚██╗ ██╔╝██╔══╝      ██╔══╝  ██╔══██║╚██╗ ██╔╝██║   ██║██╔══██╗██║   ██║   ██╔══╝  
# ██║  ██║███████╗██║ ╚═╝ ██║╚██████╔╝ ╚████╔╝ ███████╗    ██║     ██║  ██║ ╚████╔╝ ╚██████╔╝██║  ██║██║   ██║   ███████╗
# ╚═╝  ╚═╝╚══════╝╚═╝     ╚═╝ ╚═════╝   ╚═══╝  ╚══════╝    ╚═╝     ╚═╝  ╚═╝  ╚═══╝   ╚═════╝ ╚═╝  ╚═╝╚═╝   ╚═╝   ╚══════╝
##################################################################################################################
   public function removefavorite($id)
   {
      // Pass along the ROUTE value of the previous page
      //$ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      $user = Auth::user()->id;
      $recipe = Recipe::find($id);

      $recipe->favorites()->detach($user);

      Session::flash ('success','The recipe was successfully removed to your Favorites list!');
      // return redirect()->route('recipes.index','all');
      // return redirect()->route('backend.articles.myFavorites');
      //return redirect()->route($ref);
      return redirect()->back();
   }


##################################################################################################################
# ██████╗ ███████╗███╗   ███╗ ██████╗ ██╗   ██╗███████╗    ██████╗ ██████╗ ██╗██╗   ██╗ █████╗ ████████╗███████╗
# ██╔══██╗██╔════╝████╗ ████║██╔═══██╗██║   ██║██╔════╝    ██╔══██╗██╔══██╗██║██║   ██║██╔══██╗╚══██╔══╝██╔════╝
# ██████╔╝█████╗  ██╔████╔██║██║   ██║██║   ██║█████╗      ██████╔╝██████╔╝██║██║   ██║███████║   ██║   █████╗  
# ██╔══██╗██╔══╝  ██║╚██╔╝██║██║   ██║╚██╗ ██╔╝██╔══╝      ██╔═══╝ ██╔══██╗██║╚██╗ ██╔╝██╔══██║   ██║   ██╔══╝  
# ██║  ██║███████╗██║ ╚═╝ ██║╚██████╔╝ ╚████╔╝ ███████╗    ██║     ██║  ██║██║ ╚████╔╝ ██║  ██║   ██║   ███████╗
# ╚═╝  ╚═╝╚══════╝╚═╝     ╚═╝ ╚═════╝   ╚═══╝  ╚══════╝    ╚═╝     ╚═╝  ╚═╝╚═╝  ╚═══╝  ╚═╝  ╚═╝   ╚═╝   ╚══════╝
##################################################################################################################
   public function removeprivate($id)
   {
      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      $article = Article::find($id);
         $article->personal = 0;
      $article->save();

      // Save entry to log file using built-in Monolog
      //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") REMOVE PRIVATE from recipe (" . $recipe->id . ")\r\n", 
      //    [json_decode($recipe, true)]
      //);

      Session::flash('success','The article was removed from private successfully');
      return redirect()->route($ref);
   }


##################################################################################################################
# ██████╗ ███████╗███████╗███████╗████████╗    ██╗   ██╗██╗███████╗██╗    ██╗███████╗
# ██╔══██╗██╔════╝██╔════╝██╔════╝╚══██╔══╝    ██║   ██║██║██╔════╝██║    ██║██╔════╝
# ██████╔╝█████╗  ███████╗█████╗     ██║       ██║   ██║██║█████╗  ██║ █╗ ██║███████╗
# ██╔══██╗██╔══╝  ╚════██║██╔══╝     ██║       ╚██╗ ██╔╝██║██╔══╝  ██║███╗██║╚════██║
# ██║  ██║███████╗███████║███████╗   ██║        ╚████╔╝ ██║███████╗╚███╔███╔╝███████║
# ╚═╝  ╚═╝╚══════╝╚══════╝╚══════╝   ╚═╝         ╚═══╝  ╚═╝╚══════╝ ╚══╝╚══╝ ╚══════╝
// RESET VIEWS COUNT
##################################################################################################################
   public function resetViews($id)
   {
      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      $recipe = Recipe::find($id);
         $recipe->views = 0;
      $recipe->save();

      // Save entry to log file using built-in Monolog
      //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") MADE recipe (" . $recipe->id . ") PRIVATE \r\n", [json_decode($recipe, true)]);

      Session::flash('success','The recipe\'s views count was reset to 0.');
      return redirect()->route($ref);
   }


##################################################################################################################
# ██████╗ ███████╗███████╗████████╗ ██████╗ ██████╗ ███████╗
# ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
# ██████╔╝█████╗  ███████╗   ██║   ██║   ██║██████╔╝█████╗  
# ██╔══██╗██╔══╝  ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝  
# ██║  ██║███████╗███████║   ██║   ╚██████╔╝██║  ██║███████╗
# ╚═╝  ╚═╝╚══════╝╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
// RESTORE TRASHED FILE
##################################################################################################################
   public function restore($id)
   {
      $recipe = Recipe::withTrashed()->findOrFail($id);

      //$article->deleted_at = NULL;
      //$article->save();
      $recipe->restore();

      Session::flash ('success','The recipe was successfully restored.');
      return redirect()->route('backend.recipes.trashed');
   }


##################################################################################################################
# ██████╗ ███████╗███████╗████████╗ ██████╗ ██████╗ ███████╗     █████╗ ██╗     ██╗     
# ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝    ██╔══██╗██║     ██║     
# ██████╔╝█████╗  ███████╗   ██║   ██║   ██║██████╔╝█████╗      ███████║██║     ██║     
# ██╔══██╗██╔══╝  ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝      ██╔══██║██║     ██║     
# ██║  ██║███████╗███████║   ██║   ╚██████╔╝██║  ██║███████╗    ██║  ██║███████╗███████╗
# ╚═╝  ╚═╝╚══════╝╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝    ╚═╝  ╚═╝╚══════╝╚══════╝
// RESTORE ALL TRASHED FILE
##################################################################################################################
   public function restoreAll(Request $request)
   {
      //dd('TEST_RESTORE');
      //dd($request);
      //$this->validate($request, [
      //    'checked' => 'required',
      //]);
      //dd('TEST_RESTORE');

      $checked = $request->input('checked');
      //dd($checked);

      // $article = new Article();
      // $article->restore($checked);
      Recipe::whereIn('id', $checked)->restore();

      Session::flash('success','The recipes were restored successfully.');
      return redirect()->route('backend.recipes.trashed');
   }


##################################################################################################################
# ███████╗██╗  ██╗ ██████╗ ██╗    ██╗
# ██╔════╝██║  ██║██╔═══██╗██║    ██║
# ███████╗███████║██║   ██║██║ █╗ ██║
# ╚════██║██╔══██║██║   ██║██║███╗██║
# ███████║██║  ██║╚██████╔╝╚███╔███╔╝
# ╚══════╝╚═╝  ╚═╝ ╚═════╝  ╚══╝╚══╝ 
// Display the specified resource
##################################################################################################################
   public function show($id)
   {
      // if(!checkACL('guest')) {
      //     return view('errors.403');
      // }

      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();
      //dd($ref);

      $recipe = Recipe::withTrashed()->findOrFail($id);

      // Add 1 to views column
      //DB::table('articles')->where('id','=',$article->id)->increment('views',1);

      // Save entry to log file using built-in Monolog
      // if (Auth::check()) {
      //     Log::info(Auth::user()->username . " (" . Auth::user()->id . ") VIEWED article (" . $article->id . ")");
      // } else {
      //     Log::info('Guest viewed article (' . $article->id) . ')';
      // }

      return view('backend.recipes.show', compact('recipe'))->withRef($ref);
   }


##################################################################################################################
# ███████╗████████╗ ██████╗ ██████╗ ███████╗
# ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
# ███████╗   ██║   ██║   ██║██████╔╝█████╗  
# ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝  
# ███████║   ██║   ╚██████╔╝██║  ██║███████╗
# ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
// Store a newly created resource in storage
##################################################################################################################
   public function store(CreateRecipeRequest $request)
   {
      // if(!checkACL('author')) {
      //     return view('errors.403');
      // }

      $recipe = new Recipe;
         $recipe->title = $request->title;
         $recipe->ingredients = Purifier::clean($request->ingredients);
         $recipe->methodology = Purifier::clean($request->methodology);
         $recipe->category_id = $request->category_id;
         $recipe->published_at = $request->published_at;
         $recipe->servings = $request->servings;
         $recipe->prep_time = $request->prep_time;
         $recipe->cook_time = $request->cook_time;
         $recipe->personal = $request->personal;
         $recipe->source = $request->source;
         $recipe->author_notes = $request->author_notes;
         $recipe->public_notes = $request->public_notes;
         $recipe->modified_by_id = Auth::user()->id;
         $recipe->last_viewed_by_id = Auth::user()->id;
         $recipe->last_viewed_on = Carbon::Now();
         $recipe->user_id = Auth::user()->id;
      $recipe->save();

      // Save entry to log file using built-in Monolog
      //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") CREATED article (" . $article->id . ")\r\n", [json_decode($article, true)]
      //);

      Session::flash('success','The article has been created successfully!');
      return redirect()->route($request->ref);
   }


##################################################################################################################
# ████████╗██████╗  █████╗ ███████╗██╗  ██╗███████╗██████╗ 
# ╚══██╔══╝██╔══██╗██╔══██╗██╔════╝██║  ██║██╔════╝██╔══██╗
#    ██║   ██████╔╝███████║███████╗███████║█████╗  ██║  ██║
#    ██║   ██╔══██╗██╔══██║╚════██║██╔══██║██╔══╝  ██║  ██║
#    ██║   ██║  ██║██║  ██║███████║██║  ██║███████╗██████╔╝
#    ╚═╝   ╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝╚══════╝╚═════╝ 
// Display a list of resources that have been trashed (Soft Deleted)
##################################################################################################################
   public function trashed(Request $request)
   {
      // if(!checkACL('guest')) {
      //     return view('errors.403');
      // }

      $recipes = Recipe::with('user','category')->onlyTrashed()->get();
      return view('backend.recipes.trashed', compact('recipes'));
   }


##################################################################################################################
# ████████╗██████╗  █████╗ ███████╗██╗  ██╗     █████╗ ██╗     ██╗     
# ╚══██╔══╝██╔══██╗██╔══██╗██╔════╝██║  ██║    ██╔══██╗██║     ██║     
#    ██║   ██████╔╝███████║███████╗███████║    ███████║██║     ██║     
#    ██║   ██╔══██╗██╔══██║╚════██║██╔══██║    ██╔══██║██║     ██║     
#    ██║   ██║  ██║██║  ██║███████║██║  ██║    ██║  ██║███████╗███████╗
#    ╚═╝   ╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝    ╚═╝  ╚═╝╚══════╝╚══════╝
// Remove the specified resource from storage
// Used in the index page to soft delete multiple records
##################################################################################################################
   public function trashAll(Request $request)
   {
      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      $this->validate($request, [
         'checked' => 'required',
      ]);

      $checked = $request->input('checked');
      //dd($checked);

      Recipe::destroy($checked);

      Session::flash('success','The recipes were trashed successfully.');
      return redirect()->route($ref);
   }


##################################################################################################################
# ██╗   ██╗███╗   ██╗██████╗ ██╗   ██╗██████╗ ██╗     ██╗███████╗██╗  ██╗
# ██║   ██║████╗  ██║██╔══██╗██║   ██║██╔══██╗██║     ██║██╔════╝██║  ██║
# ██║   ██║██╔██╗ ██║██████╔╝██║   ██║██████╔╝██║     ██║███████╗███████║
# ██║   ██║██║╚██╗██║██╔═══╝ ██║   ██║██╔══██╗██║     ██║╚════██║██╔══██║
# ╚██████╔╝██║ ╚████║██║     ╚██████╔╝██████╔╝███████╗██║███████║██║  ██║
#  ╚═════╝ ╚═╝  ╚═══╝╚═╝      ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚══════╝╚═╝  ╚═╝
##################################################################################################################
   public function unpublish($id)
   {
      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      $recipe = Recipe::find($id);
         $recipe->published_at = NULL;
         // $article->favoriteArticles()->delete(); // Remove associated rows from article_user (favorites table)
        
         $favorites = DB::select('select * from recipe_user where recipe_id = '. $id, [1]);
         //dd ($favorites);
         foreach($favorites as $favorite) {
            //dd($favorite);
            $recipe->favorites()->detach($favorite);
         }
      $recipe->save();

      Session::flash ('success','The recipe was successfully unpublished.');
      return redirect()->route($ref);
   }


##################################################################################################################
# ██╗   ██╗███╗   ██╗██████╗ ██╗   ██╗██████╗ ██╗     ██╗███████╗██╗  ██╗███████╗██████╗ 
# ██║   ██║████╗  ██║██╔══██╗██║   ██║██╔══██╗██║     ██║██╔════╝██║  ██║██╔════╝██╔══██╗
# ██║   ██║██╔██╗ ██║██████╔╝██║   ██║██████╔╝██║     ██║███████╗███████║█████╗  ██║  ██║
# ██║   ██║██║╚██╗██║██╔═══╝ ██║   ██║██╔══██╗██║     ██║╚════██║██╔══██║██╔══╝  ██║  ██║
# ╚██████╔╝██║ ╚████║██║     ╚██████╔╝██████╔╝███████╗██║███████║██║  ██║███████╗██████╔╝
#  ╚═════╝ ╚═╝  ╚═══╝╚═╝      ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚══════╝╚═╝  ╚═╝╚══════╝╚═════╝ 
// Display a list of resources that have not been published
##################################################################################################################
   public function unpublished(Request $request, $key=null)
   {
      if(!checkACL('editor')) {
          return view('errors.403');
      }

      //$alphas = range('A', 'Z');
        $alphas = DB::table('recipes')
         ->select(DB::raw('DISTINCT LEFT(title, 1) as letter'))
         // ->where('personal', '!=', 1)
         ->where('published_at','=', null)
         ->orderBy('letter')
         ->get();
         //dd($alphas);

      $letters = [];
      foreach($alphas as $alpha) {
         $letters[] = $alpha->letter;
      }

      // If $key value is passed
      if ($key) {
         $recipes = Recipe::with('user','category')->unpublished()
            ->where('title', 'like', $key . '%')
            ->orderBy('title', 'asc')
            ->get();
         return view('backend.recipes.unpublished', compact('recipes','letters'));
      }

      // No $key value is passed
      $recipes = Recipe::with('user','category')->unpublished()->get();
      return view('backend.recipes.unpublished', compact('recipes','letters'));
   }


##################################################################################################################
# ██╗   ██╗███╗   ██╗██████╗ ██╗   ██╗██████╗ ██╗     ██╗███████╗██╗  ██╗     █████╗ ██╗     ██╗     
# ██║   ██║████╗  ██║██╔══██╗██║   ██║██╔══██╗██║     ██║██╔════╝██║  ██║    ██╔══██╗██║     ██║     
# ██║   ██║██╔██╗ ██║██████╔╝██║   ██║██████╔╝██║     ██║███████╗███████║    ███████║██║     ██║     
# ██║   ██║██║╚██╗██║██╔═══╝ ██║   ██║██╔══██╗██║     ██║╚════██║██╔══██║    ██╔══██║██║     ██║     
# ╚██████╔╝██║ ╚████║██║     ╚██████╔╝██████╔╝███████╗██║███████║██║  ██║    ██║  ██║███████╗███████╗
#  ╚═════╝ ╚═╝  ╚═══╝╚═╝      ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚══════╝╚═╝  ╚═╝    ╚═╝  ╚═╝╚══════╝╚══════╝
##################################################################################################################
   public function unpublishAll(Request $request)
   {
      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      $this->validate($request, [
         'checked' => 'required',
      ]);

      $checked = $request->input('checked');

      foreach ($checked as $item) {
         //dd($item);
         $recipe = Recipe::withTrashed()->find($item);
            $recipe->published_at = Null;

            // Delete related favorites
            $favorites = DB::select('select * from recipe_user where recipe_id = '. $recipe->id, [1]);
               foreach($favorites as $favorite) {
                  $recipe->favoriteRecipes()->detach($favorite);
               }
         $recipe->save();
      }
      

      Session::flash('success','The recipes were published successfully.');
      return redirect()->route($ref);
   }


##################################################################################################################
# ██╗   ██╗██████╗ ██████╗  █████╗ ████████╗███████╗
# ██║   ██║██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██╔════╝
# ██║   ██║██████╔╝██║  ██║███████║   ██║   █████╗  
# ██║   ██║██╔═══╝ ██║  ██║██╔══██║   ██║   ██╔══╝  
# ╚██████╔╝██║     ██████╔╝██║  ██║   ██║   ███████╗
#  ╚═════╝ ╚═╝     ╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚══════╝
// UPDATE :: Update the specified resource in storage
##################################################################################################################
   public function update(UpdateRecipeRequest $request, $id)
   {
      // Get the recipe values from the database
      $recipe = Recipe::find($id);

      // save the data in the database
      $recipe->title = $request->title;
      $recipe->ingredients = Purifier::clean($request->ingredients);
      $recipe->methodology = Purifier::clean($request->methodology);
      $recipe->category_id = $request->category_id;
      $recipe->published_at = $request->published_at;
      $recipe->servings = $request->servings;
      $recipe->prep_time = $request->prep_time;
      $recipe->cook_time = $request->cook_time;
      $recipe->personal = $request->personal;
      $recipe->source = $request->source;
      $recipe->author_notes = $request->author_notes;
      $recipe->public_notes = $request->public_notes;
      $recipe->modified_by_id = Auth::user()->id;
      $recipe->last_viewed_by_id = Auth::user()->id;
      $recipe->last_viewed_on = Carbon::Now();

      // Check if a new image was submitted
      if ($request->hasFile('image')) {
         //Add new photo
         $image = $request->file('image');
         $filename = time() . '.' . $image->getClientOriginalExtension();
         $location = public_path('_recipes/' . $filename);
         Image::make($image)->resize(800, 400)->save($location);

         // get name of old image
         $oldImageName = $recipe->image;
         //dd($oldImageName);

         // Update database
         $recipe->image = $filename;

         // Delete old photo
         //Storage::delete($oldImageName);
         File::delete('_recipes/'.$oldImageName);
      }

      $recipe->save();

      // Save entry to log file using built-in Monolog
      //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") updated :: Recipe (" . $recipe->id .")");

      // set a flash message to be displayed on screen
      Session::flash('success','The recipe was successfully updated!');
      // redirect to another page
      return redirect()->route('backend.recipes.index');
  }


##################################################################################################################
   // Display the specified trashed resource
##################################################################################################################
   // public function showTrashed($id)
   // {
   //     // if(!checkACL('guest')) {
   //     //     return view('errors.403');
   //     // }

   //     $article = Article::withTrashed()->findOrFail($id);
   //     //dd($article);

   //     // Add 1 to views column
   //     //DB::table('articles')->where('id','=',$article->id)->increment('views',1);

   //     // Save entry to log file using built-in Monolog
   //     // if (Auth::check()) {
   //     //     Log::info(Auth::user()->username . " (" . Auth::user()->id . ") VIEWED article (" . $article->id . ")");
   //     // } else {
   //     //     Log::info('Guest viewed article (' . $article->id) . ')';
   //     // }

   //     return view('backend.articles.showTrashed', compact('article'));
   // }


}
<file_sep><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Product;
use Config;
use Session;

class ProductsController extends Controller
{

	public function index()
	{
		$products = Product::sortable()
			->orderBy('code','asc')
			->paginate(Config::get('settings.rowsPerPage'));
		return view('invoicer.products.index', compact('products'));
	}


	public function create()
	{
		return view('invoicer.products.create');
	}


	public function store(Request $request)
	{
		// validate the data
		$this->validate($request, array(
			'code' => 'required|unique:products,code',
			'details' => 'required',
		));

		// save the data in the database
		$product = new Product;
			$product->code = $request->code;
			$product->details = $request->details;
		$product->save();

		// set a flash message to be displayed on screen
		Session::flash('success','The product was successfully saved!');

		// redirect to another page
	   return redirect()->route('invoicer.products.index');
	}


	public function show($id)
	{
		$product = Product::findOrFail($id);
		return view('invoicer.products.show', compact('product'));
	}


	public function edit($id)
	{
		$product = Product::findOrFail($id);
		return view('invoicer.products.edit', compact('product'));
	}


	public function update(Request $request, $id)
	{
		// validate the data
		$this->validate($request, array(
			'code' => 'required|unique:products,code,' . $id,
			// 'code' => 'required',
			'details' => 'required',
		));

		$product = Product::find($id);
			$product->code = $request->code;
			$product->details = $request->details;
		$product->save();
		
		// Set flash data with success message
		Session::flash ('success', 'The product was successfully updated!');

		// Redirect
		return redirect()->route('invoicer.products.index');
	}


	public function destroy($id)
	{
		$product = Product::find($id);
		$product->delete();

		// Set flash data with success message
		Session::flash('success','The product was deleted successfully.');

		// Redirect
		return redirect()->route('invoicer.products.index');
	}


	public function search(Request $request)
	{
		//dd($request->q);
		if($request->selection == 'code') {
			$products = Product::where('code', 'like', '%' . $request->searchWord . '%')->paginate(10);
		}

		if($request->selection == 'details') {
			$products = Product::where('details', 'like', $request->searchWord . '%')->paginate(10);
		}
		
		return view('invoicer.products.index', compact('products'));
	}

}
<file_sep><?php

use Illuminate\Database\Seeder;

class GalleryTableSeeder extends Seeder
{

    /**
     * Auto generated seed file
     *
     * @return void
     */
    public function run()
    {
        

        \DB::table('gallery')->delete();
        
        
        
    }
}<file_sep><?php

namespace App\Http\Controllers\Frontend;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use App\Comment;
use App\WoodProject;
use Auth;
use DB;
use Session;

use App\Http\Requests\CreateCommentRequest;

class WoodProjectsController extends Controller
{

##################################################################################################################
#  ██████╗ ██████╗ ███╗   ██╗███████╗████████╗██████╗ ██╗   ██╗ ██████╗████████╗
# ██╔════╝██╔═══██╗████╗  ██║██╔════╝╚══██╔══╝██╔══██╗██║   ██║██╔════╝╚══██╔══╝
# ██║     ██║   ██║██╔██╗ ██║███████╗   ██║   ██████╔╝██║   ██║██║        ██║   
# ██║     ██║   ██║██║╚██╗██║╚════██║   ██║   ██╔══██╗██║   ██║██║        ██║   
# ╚██████╗╚██████╔╝██║ ╚████║███████║   ██║   ██║  ██║╚██████╔╝╚██████╗   ██║   
#  ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝  ╚═════╝   ╚═╝   
##################################################################################################################


##################################################################################################################
# ██╗███╗   ██╗██████╗ ███████╗██╗  ██╗
# ██║████╗  ██║██╔══██╗██╔════╝╚██╗██╔╝
# ██║██╔██╗ ██║██║  ██║█████╗   ╚███╔╝ 
# ██║██║╚██╗██║██║  ██║██╔══╝   ██╔██╗ 
# ██║██║ ╚████║██████╔╝███████╗██╔╝ ██╗
# ╚═╝╚═╝  ╚═══╝╚═════╝ ╚══════╝╚═╝  ╚═╝
// Display a list of resources
##################################################################################################################
	public function index()
	{
		//$projects = Project::with('Images')->get();
		// $projects = WoodProject::orderBy('name','asc')->get();
		$projects = WoodProject::orderBy('name','asc')->paginate(8);
		//dd($projects);
		return view('frontend.woodProjects.index', compact('projects'));
	}


##################################################################################################################
# ███████╗██╗  ██╗ ██████╗ ██╗    ██╗
# ██╔════╝██║  ██║██╔═══██╗██║    ██║
# ███████╗███████║██║   ██║██║ █╗ ██║
# ╚════██║██╔══██║██║   ██║██║███╗██║
# ███████║██║  ██║╚██████╔╝╚███╔███╔╝
# ╚══════╝╚═╝  ╚═╝ ╚═════╝  ╚══╝╚══╝ 
// Display the specified resource
##################################################################################################################
	public function show($id) {
		// $project = Project::with('ImageProject')->find($id);
		$project = WoodProject::find($id);
		// dd($project);

		// get previous project id
		$previous = WoodProject::where('id', '<', $project->id)->max('id');

		// get next project id
		$next = WoodProject::where('id', '>', $project->id)->min('id');
		  
		// Add 1 to views column
		DB::table('woodprojects')->where('id','=',$project->id)->increment('views',1);

		return view('frontend.woodProjects.show', compact('project','previous','next'));
	}


##################################################################################################################
# ███████╗████████╗ ██████╗ ██████╗ ███████╗     ██████╗ ██████╗ ███╗   ███╗███╗   ███╗███████╗███╗   ██╗████████╗
# ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝    ██╔════╝██╔═══██╗████╗ ████║████╗ ████║██╔════╝████╗  ██║╚══██╔══╝
# ███████╗   ██║   ██║   ██║██████╔╝█████╗      ██║     ██║   ██║██╔████╔██║██╔████╔██║█████╗  ██╔██╗ ██║   ██║   
# ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝      ██║     ██║   ██║██║╚██╔╝██║██║╚██╔╝██║██╔══╝  ██║╚██╗██║   ██║   
# ███████║   ██║   ╚██████╔╝██║  ██║███████╗    ╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ╚═╝ ██║███████╗██║ ╚████║   ██║   
# ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝     ╚═════╝ ╚═════╝ ╚═╝     ╚═╝╚═╝     ╚═╝╚══════╝╚═╝  ╚═══╝   ╚═╝   
##################################################################################################################
	// public function storeComment(CreateCommentRequest $request, $id)
	public function storeComment(CreateCommentRequest $request, $id)
	{
		//dd($id);
		$project = woodProject::find($id);
		//dd($project);

		$comment = new Comment();
			// $comment->name = $request->name;
			// $comment->email = $request->email;
			$comment->user_id = Auth::user()->id;
			$comment->comment = $request->comment;
			$project->comments()->save($comment);
		$comment->save();

		// Save entry to log file using built-in Monolog
		// if (Auth::check()) {
		//     Log::info(Auth::user()->username . " (" . Auth::user()->id . ") commented on post (" . $post->id . ")\r\n", [json_decode($comment, true)]);
		// } else {
		//     Log::info(Request::ip() . " commented on post " . $post->id);
		// }

		Session::flash('success', 'Comment added succesfully.');
		return redirect()->route('woodProjects.show', $project->id);
	}


}
<file_sep><?php

namespace App\Http\Controllers\Backend;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Storage;
use App\Photo;
use Session;
use Image;
use File;

class PhotosController extends Controller
{

##################################################################################################################
#  ██████╗ ██████╗ ███╗   ██╗███████╗████████╗██████╗ ██╗   ██╗ ██████╗████████╗
# ██╔════╝██╔═══██╗████╗  ██║██╔════╝╚══██╔══╝██╔══██╗██║   ██║██╔════╝╚══██╔══╝
# ██║     ██║   ██║██╔██╗ ██║███████╗   ██║   ██████╔╝██║   ██║██║        ██║   
# ██║     ██║   ██║██║╚██╗██║╚════██║   ██║   ██╔══██╗██║   ██║██║        ██║   
# ╚██████╗╚██████╔╝██║ ╚████║███████║   ██║   ██║  ██║╚██████╔╝╚██████╗   ██║   
#  ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝  ╚═════╝   ╚═╝   
##################################################################################################################
	public function __construct() {
		// only allow authenticated users to access these pages
		//$this->middleware('auth', ['except'=>['index','show']]);
		// changing auth to guest would only allow guests to access these pages
		// you can also restrict the actions by adding ['except' => 'name_of_action'] at the end
		$this->middleware('auth');

		//Log::useFiles(storage_path().'/logs/articles.log');
		//Log::useFiles(storage_path().'/logs/audits.log');
	}


##################################################################################################################
#  ██████╗██████╗ ███████╗ █████╗ ████████╗███████╗
# ██╔════╝██╔══██╗██╔════╝██╔══██╗╚══██╔══╝██╔════╝
# ██║     ██████╔╝█████╗  ███████║   ██║   █████╗  
# ██║     ██╔══██╗██╔══╝  ██╔══██║   ██║   ██╔══╝  
# ╚██████╗██║  ██║███████╗██║  ██║   ██║   ███████╗
#  ╚═════╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝   ╚═╝   ╚══════╝
// Show the form for creating a new resource
##################################################################################################################
	public function create($album_id) {
		return view('backend.photos.create', compact('album_id'));
	}


##################################################################################################################
# ███████╗████████╗ ██████╗ ██████╗ ███████╗
# ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
# ███████╗   ██║   ██║   ██║██████╔╝█████╗  
# ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝  
# ███████║   ██║   ╚██████╔╝██║  ██║███████╗
# ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
// Store a newly created resource in storage
##################################################################################################################
	public function store(Request $request) {
		$this->validate($request, [
			'ori_name' => 'required',
			'new_name' => 'image|max:1999'
		]);

		// Get the file object
		$file = $request->file('photo');

		// Get file name with extension
		$filenameWithExt = $request->file('photo')->getClientOriginalName();

		// Get just the filename
		$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);

		// Get the extension
		$extension = $request->file('photo')->getClientOriginalExtension();

		// Create the new filename
		$filenameToStore = $filename . '_' . time() . '.' . $extension;
		//dd($filenameToStore);
		// Upload image
		// Check if Gallery/Images folders exists
		if (!file_exists('_albums/images/'.$request->input('album_id'))) {
			mkdir('_albums/images/' . $request->input('album_id'), 0777, true);
		}

		// move the file to the correct location
		$file->move('_albums/images/' . $request->input('album_id') . "/", $filenameToStore);
		
		// Check if Thumbs folder exists under Images
		if (!file_exists('_albums/images/thumbs/'.$request->input('album_id'))) {
			mkdir('_albums/images/thumbs/' . $request->input('album_id'), 0777, true);
		}

		// Create thumbnail
		$thumb = Image::make('_albums/images/' . $request->input('album_id') . "/" . $filenameToStore)
			->resize(240,160)
			->save('_albums/images/thumbs/' . $request->input('album_id') . "/" . $filenameToStore, 60);


		//Create photo record in DB
		$photo = new Photo;
			$photo->album_id = $request->input('album_id');
			$photo->ori_name = $request->input('ori_name');
			$photo->new_name = $filenameToStore;            
			$photo->size = $request->file('photo')->getClientSize();
			$photo->description = $request->input('description');
		$photo->save();

		Session::flash('success','Photo uploaded.');
		return redirect('/backend/albums/'. $request->input('album_id'));
	}


##################################################################################################################
# ███████╗██╗  ██╗ ██████╗ ██╗    ██╗
# ██╔════╝██║  ██║██╔═══██╗██║    ██║
# ███████╗███████║██║   ██║██║ █╗ ██║
# ╚════██║██╔══██║██║   ██║██║███╗██║
# ███████║██║  ██║╚██████╔╝╚███╔███╔╝
# ╚══════╝╚═╝  ╚═╝ ╚═════╝  ╚══╝╚══╝ 
// Display the specified resource
##################################################################################################################
	public function show($id) {
		$photo = Photo::find($id);
		return view('backend.photos.show', compact('photo'));
	}


##################################################################################################################
# ██████╗ ███████╗███████╗████████╗██████╗  ██████╗ ██╗   ██╗
# ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔══██╗██╔═══██╗╚██╗ ██╔╝
# ██║  ██║█████╗  ███████╗   ██║   ██████╔╝██║   ██║ ╚████╔╝ 
# ██║  ██║██╔══╝  ╚════██║   ██║   ██╔══██╗██║   ██║  ╚██╔╝  
# ██████╔╝███████╗███████║   ██║   ██║  ██║╚██████╔╝   ██║   
# ╚═════╝ ╚══════╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝    ╚═╝   
// Remove the specified resource from storage
// Used in the index page and trashAll action to soft delete multiple records
##################################################################################################################
	public function destroy($id) {
		$photo = Photo::find($id);

		unlink(public_path('_albums/images/' . $photo->album->id . "/" . $photo->new_name));
		unlink(public_path('_albums/images/thumbs/' . $photo->album->id . "/" . $photo->new_name));
		$photo->delete();

		// Check if there are any files left in the folder, if not, delete the folder and thumbs folder
		if (count(glob('_albums/images/' . $photo->album->id . "/*")) === 0 ) { // empty
			// Delete the IMAGES/THUMBS folder matching the album id
			File::deleteDirectory(public_path('_albums/images/thumbs/' . $photo->album_id));
			// Delete the IMAGES folder matching the album id
			File::deleteDirectory(public_path('_albums/images/' . $photo->album_id));
		}
		
		Session::flash('success','Image deleted.');
		return redirect(route('backend.albums.show', $photo->album_id));
	}


}
<file_sep><?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Auth;
use App\Category;
//use App\Recipe;
use Carbon\Carbon;

class Recipe extends Model
{

   use SoftDeletes;

   protected $dates = ['deleted_at', 'published_at'];

   // protected $fillable = [
   //    'title',
   //    'ingredients',
   //    'methodology',
   //    'image',
   //    'category_id',
   //    'servings',
   //    'prep_time',
   //    'cook_time',
   //    'personal',
   //    'views',
   //    'source',
   //    'author_notes',
   //    'publis_notes',
   //    'user_id',
   //    'modified_by_id',
   //    'last_viewed_by_id',
   //    'published_at',
   //    'last_viewd_on'      
   // ];

   public function comments()
   {
      return $this->morphMany('\App\Comment', 'commentable')->orderBy('id','desc');
   }
   
	public function user()
   {
      return $this->belongsTo('App\User');
   }

   public function modifiedBy()
   {
      return $this->belongsTo('App\User');
   }

   public function lastViewedBy()
   {
      return $this->belongsTo('App\User');
   }

   public function category()
   {
      return $this->belongsTo('App\Category');
   }

   // used in the add and remove favorite
   public function favorites()
   {
      return $this->belongsToMany('App\User')->where('user_id','=',Auth::user()->id);
      // return $this->belongsToMany('App\User');
   }

   public function scopePublished($query)
   {
      return $query->where('published_at', '<', Carbon::now());
   }
   
   public function scopeUnpublished($query)
   {
      return $query
         ->where('published_at', '=', NULL);
   }

   public function scopeTrashed($query)
   {
      return $query->where('deleted_at', '!=', NULL)->withTrashed();
   }

   public function scopeTrashedCount($query)
   {
      return $query->whereNotNull('deleted_at')->withTrashed();
   }
   
   public function scopeMyRecipes($query)
   {
      return $query
         ->where('user_id', '=', Auth::user()->id)
         ->orderBy('title','DESC');
   }

   public function scopeNewRecipes($query)
   {
      return $query
         ->where('created_at', '>=' , Auth::user()->last_login_date)
         //->where('user_id', '=', Auth::user()->id)
         ->orderBy('title','DESC');
   }

   public function scopeFuture($query)
   {
      return $query
         ->where('published_at', '>', Carbon::Now());
   }
   
}
<file_sep><?php

Route::group(['prefix'=>'backend/modules'], function()
{
	$c = 'Backend\ModulesController@';
	$r = 'backend.modules.';

	Route::get('{id}/delete',						['uses' => $c . 'delete',					'as' => $r . 'delete']);
	Route::get('exportPDF',							['uses' => $c . 'exportPDF',				'as' => $r . 'exportPDF']);
	Route::get('import',								['uses' => $c . 'import',					'as' => $r . 'import']);
	Route::get('downloadExcel/{type}',			['uses' => $c . 'downloadExcel',			'as' => $r . 'downloadExcel']);
	Route::post('importExcel',						['uses' => $c . 'importExcel',			'as' => $r . 'importExport']);
	Route::get('newModules',  			         ['uses' => $c . 'newModules',			   'as' => $r . 'newModules']);

	Route::get('create',								['uses' => $c . 'create',					'as' => $r . 'create']);
	Route::post('modules',							['uses' => $c . 'store',					'as' => $r . 'store']);
	Route::get('',										['uses' => $c . 'index',					'as' => $r . 'index']);
	Route::get('{id}/edit',							['uses' => $c . 'edit',						'as' => $r . 'edit']);
	Route::put('{id}',								['uses' => $c . 'update',					'as' => $r . 'update']);
	Route::delete('{id}',							['uses' => $c . 'destroy',					'as' => $r . 'destroy']);

});<file_sep><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
// use App\Modules\Invoicer\Models\Ledger;
use App\Invoice;
use Config;
use DB;

class LedgerController extends Controller
{

	public function index()
	{
		$invoices = Invoice::sortable()
			->orderBy('id','desc')
			->paginate(Config::get('settings.rowsPerPage'))
			;
		$totalAmountCharged = DB::table('invoices')->sum('amount_charged');
		$totalHST = DB::table('invoices')->sum('hst');
		$totalSubTotal = DB::table('invoices')->sum('sub_total');
		$totalWSIB = DB::table('invoices')->sum('wsib');
		$totalIncomeTaxes = DB::table('invoices')->sum('income_taxes');
		$totalTotalDeductions = DB::table('invoices')->sum('total_deductions');
		$totalTotal = DB::table('invoices')->sum('total');
		// dd($invoices);
		return view('invoicer.ledger.index', compact('invoices','totalHST','totalAmountCharged','totalSubTotal', 'totalWSIB', 'totalIncomeTaxes','totalTotalDeductions', 'totalTotal'));
	}

	public function paid()
	{
		$invoices = Invoice::sortable()->where('status','=','paid')
			->paginate(Config::get('settings.rowsPerPage'));
		$totalAmountCharged = DB::table('invoices')->where('status','=','paid')->sum('amount_charged');
		$totalHST = DB::table('invoices')->where('status','=','paid')->sum('hst');
		$totalSubTotal = DB::table('invoices')->where('status','=','paid')->sum('sub_total');
		$totalWSIB = DB::table('invoices')->where('status','=','paid')->sum('wsib');
		$totalIncomeTaxes = DB::table('invoices')->where('status','=','paid')->sum('income_taxes');
		$totalTotalDeductions = DB::table('invoices')->where('status','=','paid')->sum('total_deductions');
		$totalTotal = DB::table('invoices')->where('status','=','paid')->sum('total');

		return view('invoicer.ledger.index', compact('invoices','totalHST','totalAmountCharged','totalSubTotal', 'totalWSIB', 'totalIncomeTaxes','totalTotalDeductions', 'totalTotal'));
	}

	public function invoiced()
	{
		$invoices = Invoice::sortable()->where('status','=','invoiced')
			->paginate(Config::get('settings.rowsPerPage'));
		$totalAmountCharged = DB::table('invoices')->where('status','=','invoiced')->sum('amount_charged');
		$totalHST = DB::table('invoices')->where('status','=','invoiced')->sum('hst');
		$totalSubTotal = DB::table('invoices')->where('status','=','invoiced')->sum('sub_total');
		$totalWSIB = DB::table('invoices')->where('status','=','invoiced')->sum('wsib');
		$totalIncomeTaxes = DB::table('invoices')->where('status','=','invoiced')->sum('income_taxes');
		$totalTotalDeductions = DB::table('invoices')->where('status','=','invoiced')->sum('total_deductions');
		$totalTotal = DB::table('invoices')->where('status','=','invoiced')->sum('total');

		return view('invoicer.ledger.index', compact('invoices','totalHST','totalAmountCharged','totalSubTotal', 'totalWSIB', 'totalIncomeTaxes','totalTotalDeductions', 'totalTotal'));
	}

	public function logged()
	{
		$invoices = Invoice::sortable()->where('status','=','logged')
			->paginate(Config::get('settings.rowsPerPage'));
		$totalAmountCharged = DB::table('invoices')->where('status','=','logged')->sum('amount_charged');
		$totalHST = DB::table('invoices')->where('status','=','logged')->sum('hst');
		$totalSubTotal = DB::table('invoices')->where('status','=','logged')->sum('sub_total');
		$totalWSIB = DB::table('invoices')->where('status','=','logged')->sum('wsib');
		$totalIncomeTaxes = DB::table('invoices')->where('status','=','logged')->sum('income_taxes');
		$totalTotalDeductions = DB::table('invoices')->where('status','=','logged')->sum('total_deductions');
		$totalTotal = DB::table('invoices')->where('status','=','logged')->sum('total');

		return view('invoicer.ledger.index', compact('invoices','totalHST','totalAmountCharged','totalSubTotal', 'totalWSIB', 'totalIncomeTaxes','totalTotalDeductions', 'totalTotal'));
	}

}
<file_sep><?php

namespace App\Listeners;

use App\Models\User;
use Carbon\Carbon;
use Illuminate\Auth\Events\Login;

class IncreaseLoginCount
{
    /**
     * Handle the event.
     *
     * @param  \Illuminate\Auth\Events\Login $event
     * @return void
     */
    public function handle(Login $event)
    {
        // Update user login count
        $event->user->increment('login_count', 1);
    }
}<file_sep><?php

namespace App\Http\Controllers;

use App\CsvData;
use App\Item;

use Illuminate\Http\Request;

use App\Http\Controllers\Controller;
use App\Http\Requests\CsvImportRequest;

use Maatwebsite\Excel\Facades\Excel;

class ItemsController extends Controller
{

##################################################################################################################
# ██╗███╗   ██╗██████╗ ███████╗██╗  ██╗
# ██║████╗  ██║██╔══██╗██╔════╝╚██╗██╔╝
# ██║██╔██╗ ██║██║  ██║█████╗   ╚███╔╝ 
# ██║██║╚██╗██║██║  ██║██╔══╝   ██╔██╗ 
# ██║██║ ╚████║██████╔╝███████╗██╔╝ ██╗
# ╚═╝╚═╝  ╚═══╝╚═════╝ ╚══════╝╚═╝  ╚═╝
// Display a list of resources
##################################################################################################################
	public function index()
	{
		if(!checkACL('guest')) {
			 return view('errors.403');
			// abort(403);
		}

		$items = Item::all();
		return view('items.index', compact('items'));
	}


	public function published()
	{
		$items = Item::where('status',1)->get();
		//dd($items);
		return view('items.index', compact('items'));
	}

	public function unpublished()
	{
		$items = Item::where('status',2)->get();
		//dd($items);
		return view('items.index', compact('items'));
	}

	public function future()
	{
		$items = Item::where('status',3)->get();
		//dd($items);
		return view('items.index', compact('items'));
	}

	public function trashed()
	{
		$items = Item::where('status',4)->get();
		//dd($items);
		return view('items.index', compact('items'));
	}

##################################################################################################################
#  ██████╗██████╗ ███████╗ █████╗ ████████╗███████╗
# ██╔════╝██╔══██╗██╔════╝██╔══██╗╚══██╔══╝██╔════╝
# ██║     ██████╔╝█████╗  ███████║   ██║   █████╗  
# ██║     ██╔══██╗██╔══╝  ██╔══██║   ██║   ██╔══╝  
# ╚██████╗██║  ██║███████╗██║  ██║   ██║   ███████╗
#  ╚═════╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝   ╚═╝   ╚══════╝
// Show the form for creating a new resource
##################################################################################################################
	public function create()
	{
		//
	}


##################################################################################################################
# ███████╗████████╗ ██████╗ ██████╗ ███████╗
# ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
# ███████╗   ██║   ██║   ██║██████╔╝█████╗  
# ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝  
# ███████║   ██║   ╚██████╔╝██║  ██║███████╗
# ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
// Store a newly created resource in storage
##################################################################################################################
	public function store(Request $request)
	{
		//
	}


##################################################################################################################
# ███████╗██╗  ██╗ ██████╗ ██╗    ██╗
# ██╔════╝██║  ██║██╔═══██╗██║    ██║
# ███████╗███████║██║   ██║██║ █╗ ██║
# ╚════██║██╔══██║██║   ██║██║███╗██║
# ███████║██║  ██║╚██████╔╝╚███╔███╔╝
# ╚══════╝╚═╝  ╚═╝ ╚═════╝  ╚══╝╚══╝ 
// Display the specified resource
##################################################################################################################
	public function show(Item $item)
	{
		//
	}


##################################################################################################################
# ███████╗██████╗ ██╗████████╗
# ██╔════╝██╔══██╗██║╚══██╔══╝
# █████╗  ██║  ██║██║   ██║   
# ██╔══╝  ██║  ██║██║   ██║   
# ███████╗██████╔╝██║   ██║   
# ╚══════╝╚═════╝ ╚═╝   ╚═╝   
// Show the form for editing the specified resource
##################################################################################################################
	public function edit(Item $item)
	{
		//
	}


##################################################################################################################
# ██╗   ██╗██████╗ ██████╗  █████╗ ████████╗███████╗
# ██║   ██║██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██╔════╝
# ██║   ██║██████╔╝██║  ██║███████║   ██║   █████╗  
# ██║   ██║██╔═══╝ ██║  ██║██╔══██║   ██║   ██╔══╝  
# ╚██████╔╝██║     ██████╔╝██║  ██║   ██║   ███████╗
#  ╚═════╝ ╚═╝     ╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚══════╝
// UPDATE :: Update the specified resource in storage
##################################################################################################################
	public function update(Request $request, Item $item)
	{
		//
	}


##################################################################################################################
# ██████╗ ███████╗███████╗████████╗██████╗  ██████╗ ██╗   ██╗
# ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔══██╗██╔═══██╗╚██╗ ██╔╝
# ██║  ██║█████╗  ███████╗   ██║   ██████╔╝██║   ██║ ╚████╔╝ 
# ██║  ██║██╔══╝  ╚════██║   ██║   ██╔══██╗██║   ██║  ╚██╔╝  
# ██████╔╝███████╗███████║   ██║   ██║  ██║╚██████╔╝   ██║   
# ╚═════╝ ╚══════╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝    ╚═╝   
// Remove the specified resource from storage
// Used in the index page and trashAll action to soft delete multiple records
##################################################################################################################
	public function destroy(Item $item)
	{
		//
	}



	public function getImport()
	{
		return view('items.import.form');
	}

	public function parseImport(CsvImportRequest $request)
	{
		$path = $request->file('csv_file')->getRealPath();

		if ($request->has('header')) {
			$data = Excel::load($path, function($reader) {})->get()->toArray();
		} else {
			$data = array_map('str_getcsv', file($path));
		}

		if (count($data) > 0) {

			if ($request->has('header')) {
				$csv_header_fields = [];

				foreach ($data[0] as $key => $value) {
					$csv_header_fields[] = $key;
				}
				
			}

			$csv_data = array_slice($data, 0, 3);
			$csv_data_file = CsvData::create([
				'csv_filename' => $request->file('csv_file')->getClientOriginalName(),
				'csv_header' => $request->has('header'),
				'csv_data' => json_encode($data)
			]);

		} else {

			return redirect()->back();

		}

		return view('items.import.fields', compact( 'csv_header_fields', 'csv_data', 'csv_data_file'));
	}
	

	public function processImport(Request $request)
	{
		$data = CsvData::find($request->csv_data_file_id);
		$csv_data = json_decode($data->csv_data, true);

		foreach ($csv_data as $row) {
			$item = new Item();

			foreach (config('app.items_db_fields') as $index => $field) {
				if ($data->csv_header) {
					$item->$field = $row[$request->fields[$field]];
				} else {
					$item->$field = $row[$request->fields[$index]];
				}
			}

			$item->save();

		}

		return view('items.import.success');
	}


}



<file_sep><?php

// ALBUMS
// Route::resource('albums', 'AlbumsController');

Route::get('albums/photo/{id}',         'AlbumsController@showPhoto')         ->name('photo.show');
Route::get('photo/download/{ptf}',      'AlbumsController@download')          ->name('photo.download');
Route::get('photo/add/{album_id}',      'AlbumsController@addPhoto')          ->name('photo.add');
Route::post('photo/store',              'AlbumsController@storePhoto')        ->name('photo.store');
Route::delete('photo/{id}',             'AlbumsController@destroyPhoto')      ->name('photo.delete');

Route::get('albums/create',             'AlbumsController@create')            ->name('albums.create');
Route::get('albums/{id}/edit',          'AlbumsController@edit')              ->name('albums.edit');
Route::post('albums/{key?}',            'AlbumsController@store')             ->name('albums.store');
Route::get('albums/{id}',               'AlbumsController@show')              ->name('albums.show');
Route::get('albums/{key?}',             'AlbumsController@index')             ->name('albums.index');
Route::put('albums/update/{id}',        'AlbumsController@update')            ->name('albums.update');
Route::delete('albums/{id}',            'AlbumsController@destroy')           ->name('albums.destroy');<file_sep><?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

//Route::view('about', 'frontend.about'); // This route does not require a controller method associated to it

Auth::routes();

Route::get('/',									['uses'=>'HomeController@index',				'as'=>'homepage']);
Route::get('about',								['uses'=>'HomeController@about',				'as'=>'about']);
Route::get('members',                     ['uses'=>'HomeController@members',        'as'=>'members']);
Route::get('contact',							['uses'=>'HomeController@contact',			'as'=>'contact']);
Route::post('contact',                    ['uses'=>'HomeController@postContact',    'as'=>'postContact']);


Route::get('blog/search',                 ['uses'=>'BlogController@search',         'as'=>'blog.search']);
Route::get('blog/print/{id}',             ['uses'=>'BlogController@print',          'as'=>'blog.print']);
Route::get('blog/viewImage/{id}',         ['uses'=>'BlogController@viewImage',      'as'=>'blog.viewImage']);
Route::get('blog/{year}/{month}',         ['uses'=>'BlogController@archive',        'as'=>'blog.archive']);
Route::post('blog/{id}/storeComment',     ['uses'=>'BlogController@storeComment',   'as'=>'blog.storeComment']);
Route::get('blog/{slug}',                 ['uses'=>'BlogController@getSingle',      'as'=>'blog.single'])->where('slug', '[\w\d\-\_]+');
Route::get('blog',                        ['uses'=>'BlogController@getIndex',       'as'=>'blog.index']);

Route::get('dashboard',				['uses'=>'DashboardController@index',		'as'=>'dashboard']);

// Route::get('posts/create',          ['uses'=>'PostsController@index',     'as'=>'posts.create']);


// Include all files from app\Http\routes\ folder
foreach ( File::allFiles(__DIR__.'/routes') as $partial )
{
	 require $partial->getPathname();
}<file_sep><?php

namespace App\Http\Controllers\Frontend;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Article;
use App\Post;
use App\Recipe;
use App\User;
use App\WoodProject;
use Carbon\Carbon;
use Auth;
use DB;

use App\Mail\DemoMail;
use Mail;

class HomeController extends Controller
{

##################################################################################################################
#  ██████╗ ██████╗ ███╗   ██╗███████╗████████╗██████╗ ██╗   ██╗ ██████╗████████╗
# ██╔════╝██╔═══██╗████╗  ██║██╔════╝╚══██╔══╝██╔══██╗██║   ██║██╔════╝╚══██╔══╝
# ██║     ██║   ██║██╔██╗ ██║███████╗   ██║   ██████╔╝██║   ██║██║        ██║   
# ██║     ██║   ██║██║╚██╗██║╚════██║   ██║   ██╔══██╗██║   ██║██║        ██║   
# ╚██████╗╚██████╔╝██║ ╚████║███████║   ██║   ██║  ██║╚██████╔╝╚██████╗   ██║   
#  ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝  ╚═════╝   ╚═╝   
##################################################################################################################
	public function __construct()
	{
		//$this->middleware('auth')->except('index','about','contact');
	}


##################################################################################################################
# ██╗  ██╗ ██████╗ ███╗   ███╗███████╗██████╗  █████╗  ██████╗ ███████╗
# ██║  ██║██╔═══██╗████╗ ████║██╔════╝██╔══██╗██╔══██╗██╔════╝ ██╔════╝
# ███████║██║   ██║██╔████╔██║█████╗  ██████╔╝███████║██║  ███╗█████╗  
# ██╔══██║██║   ██║██║╚██╔╝██║██╔══╝  ██╔═══╝ ██╔══██║██║   ██║██╔══╝  
# ██║  ██║╚██████╔╝██║ ╚═╝ ██║███████╗██║     ██║  ██║╚██████╔╝███████╗
# ╚═╝  ╚═╝ ╚═════╝ ╚═╝     ╚═╝╚══════╝╚═╝     ╚═╝  ╚═╝ ╚═════╝ ╚══════╝
// Display a list of resources
##################################################################################################################
	public function index()
	{

		// Get list of articles by year and month
		$articlelinks = DB::table('articles')
			->select(DB::raw('YEAR(created_at) year, MONTH(created_at) month, MONTHNAME(created_at) month_name, COUNT(*) article_count'))
			->where('published_at', '<=', Carbon::now())
			//->where('created_at', '<=', Carbon::now()->subMonth(3))
			->groupBy('year')->groupBy('month')->orderBy('year', 'desc')->orderBy('month', 'desc')->get();

		// Get list of posts by year and month
		$postlinks = DB::table('posts')
			->select(DB::raw('YEAR(created_at) year, MONTH(created_at) month, MONTHNAME(created_at) month_name, COUNT(*) post_count'))
			->where('published_at', '<=', Carbon::now())
			->groupBy('year')->groupBy('month')->orderBy('year', 'desc')->orderBy('month', 'desc')->get();

		// Get list of recips by year and month
		$recipelinks = DB::table('recipes')
			->select(DB::raw('YEAR(published_at) year, MONTH(published_at) month, MONTHNAME(published_at) month_name, COUNT(*) recipe_count'))
			->where('published_at', '<=', Carbon::now())
			->groupBy('year')->groupBy('month')->orderBy('year', 'desc')->orderBy('month', 'desc')->get();

		$posts = Post::published()->with('user')->orderBy('created_at','desc')->take(5)->get();
		$woodprojects = WoodProject::all()->random(5);

		$popularArticle = Article::published()->get()->sortByDesc('views')->take(1);
		$popularPost = Post::published()->get()->sortByDesc('views')->take(1);
		$popularRecipe = Recipe::published()->get()->sortByDesc('views')->take(1);
		$popularWoodProject = WoodProject::get()->sortByDesc('views')->take(1);

		return view('frontend.homepage', compact('posts', 'popularArticle', 'popularPost', 'popularRecipe', 'articlelinks', 'postlinks', 'recipelinks', 'woodprojects', 'popularWoodProject'));
	}


##################################################################################################################
#  █████╗ ██████╗  ██████╗ ██╗   ██╗████████╗
# ██╔══██╗██╔══██╗██╔═══██╗██║   ██║╚══██╔══╝
# ███████║██████╔╝██║   ██║██║   ██║   ██║   
# ██╔══██║██╔══██╗██║   ██║██║   ██║   ██║   
# ██║  ██║██████╔╝╚██████╔╝╚██████╔╝   ██║   
# ╚═╝  ╚═╝╚═════╝  ╚═════╝  ╚═════╝    ╚═╝   
##################################################################################################################
	public function about()
	{
		return view('frontend.about');
	}


##################################################################################################################
#  ██████╗ ██████╗ ███╗   ██╗████████╗ █████╗  ██████╗████████╗
# ██╔════╝██╔═══██╗████╗  ██║╚══██╔══╝██╔══██╗██╔════╝╚══██╔══╝
# ██║     ██║   ██║██╔██╗ ██║   ██║   ███████║██║        ██║   
# ██║     ██║   ██║██║╚██╗██║   ██║   ██╔══██║██║        ██║   
# ╚██████╗╚██████╔╝██║ ╚████║   ██║   ██║  ██║╚██████╗   ██║   
#  ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝   ╚═╝   
##################################################################################################################
	public function contact()
	{
		return view('frontend.contact');
	}


##################################################################################################################
# ██████╗ ██╗      ██████╗  ██████╗ 
# ██╔══██╗██║     ██╔═══██╗██╔════╝ 
# ██████╔╝██║     ██║   ██║██║  ███╗
# ██╔══██╗██║     ██║   ██║██║   ██║
# ██████╔╝███████╗╚██████╔╝╚██████╔╝
# ╚═════╝ ╚══════╝ ╚═════╝  ╚═════╝ 
##################################################################################################################
	public function blog()
	{
		return view('frontend.blog.index');
	}


##################################################################################################################
# ██╗████████╗███████╗███╗   ███╗███████╗
# ██║╚══██╔══╝██╔════╝████╗ ████║██╔════╝
# ██║   ██║   █████╗  ██╔████╔██║███████╗
# ██║   ██║   ██╔══╝  ██║╚██╔╝██║╚════██║
# ██║   ██║   ███████╗██║ ╚═╝ ██║███████║
# ╚═╝   ╚═╝   ╚══════╝╚═╝     ╚═╝╚══════╝
##################################################################################################################
	public function items()
	{

		if(!checkACL('guest')) {
			 return view('errors.frontend.403');
			// abort(403);
		}
			
		return view('frontend.items.index');
	}


##################################################################################################################
# ███████╗██╗  ██╗ ██████╗ ██████╗ 
# ██╔════╝██║  ██║██╔═══██╗██╔══██╗
# ███████╗███████║██║   ██║██████╔╝
# ╚════██║██╔══██║██║   ██║██╔═══╝ 
# ███████║██║  ██║╚██████╔╝██║     
# ╚══════╝╚═╝  ╚═╝ ╚═════╝ ╚═╝     
##################################################################################################################
	public function shop()
	{
		return view('frontend.shop.index');
	}


##################################################################################################################
# ██████╗  ██████╗ ███████╗████████╗     ██████╗ ██████╗ ███╗   ██╗████████╗ █████╗  ██████╗████████╗
# ██╔══██╗██╔═══██╗██╔════╝╚══██╔══╝    ██╔════╝██╔═══██╗████╗  ██║╚══██╔══╝██╔══██╗██╔════╝╚══██╔══╝
# ██████╔╝██║   ██║███████╗   ██║       ██║     ██║   ██║██╔██╗ ██║   ██║   ███████║██║        ██║   
# ██╔═══╝ ██║   ██║╚════██║   ██║       ██║     ██║   ██║██║╚██╗██║   ██║   ██╔══██║██║        ██║   
# ██║     ╚██████╔╝███████║   ██║       ╚██████╗╚██████╔╝██║ ╚████║   ██║   ██║  ██║╚██████╗   ██║   
# ╚═╝      ╚═════╝ ╚══════╝   ╚═╝        ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝   ╚═╝   
##################################################################################################################
// public function postContact(Request $request) {
// 		// used to submit the info from the contact page to the database
// 		$this->validate($request, [
// 			'email'		=> 'required|email',
// 			'subject'	=> 'required|min:3',
// 			'message'	=> 'required|min:10'
// 		]);

// 		$data = array(
// 			'email'			=> $request->email,
// 			'subject'		=> $request->subject,
// 			'bodyMessage'	=> $request->message
// 		);

// 		// $token = $request->input('g-recaptcha-response');

// 		// if ($token) {
// 		// 	$client = new Client(); //Initialize a new Guzzle object
// 		// 	$response = $client->post('https://www.google.com/recaptcha/api/siteverify', [
// 		// 		'form_params' => array(
// 		// 			'secret' 	=> '<KEY>',
// 		// 			'response'	=> $token
// 		// 			)
// 		// 		]);
// 		// 	$results = json_decode($response->getBody()->getContents());

// 		// 	if ($results->success) {
// 		// 		Session::flash('success','Yes we know you are human');
// 		// 	} else {
// 		// 		Session::flash('error','You are probably a robot');
// 		// 	}
// 		// }

// 		// use Mail::queue() to send multiple emails at a later time
// 		Mail::send('emails.contact', $data, function($message) use ($data) {
// 			$message->from($data['email']);
// 			$message->to('<EMAIL>');
// 			$message->subject($data['subject']);
// 		}); 

// 		// Save entry to log file using built-in Monolog
// 		// if(Auth::check()) {
// 		// 	Log::info(Auth::user()->username . " (" . Auth::user()->id . ") submitted :: Contact");
// 		// }else{
// 		// 	Log::info(getClientIP() . " submitted :: Contact");
// 		// }

// 		Session::flash('success','Your email was sent!');
// 		return redirect()->url('/');
// 	}


##################################################################################################################
# ██████╗  ██████╗ ███████╗████████╗     ██████╗ ██████╗ ███╗   ██╗████████╗ █████╗  ██████╗████████╗
# ██╔══██╗██╔═══██╗██╔════╝╚══██╔══╝    ██╔════╝██╔═══██╗████╗  ██║╚══██╔══╝██╔══██╗██╔════╝╚══██╔══╝
# ██████╔╝██║   ██║███████╗   ██║       ██║     ██║   ██║██╔██╗ ██║   ██║   ███████║██║        ██║   
# ██╔═══╝ ██║   ██║╚════██║   ██║       ██║     ██║   ██║██║╚██╗██║   ██║   ██╔══██║██║        ██║   
# ██║     ╚██████╔╝███████║   ██║       ╚██████╗╚██████╔╝██║ ╚████║   ██║   ██║  ██║╚██████╗   ██║   
# ╚═╝      ╚═════╝ ╚══════╝   ╚═╝        ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝   ╚═╝   
##################################################################################################################
	public function postContact(Request $request)
	{
		$email = Auth::user()->email;
		//dd($email);
		Mail::to($email)->send(new DemoMail());
		return view('homepage');
	}


##################################################################################################################
# ███╗   ███╗███████╗███╗   ███╗██████╗ ███████╗██████╗ ███████╗
# ████╗ ████║██╔════╝████╗ ████║██╔══██╗██╔════╝██╔══██╗██╔════╝
# ██╔████╔██║█████╗  ██╔████╔██║██████╔╝█████╗  ██████╔╝███████╗
# ██║╚██╔╝██║██╔══╝  ██║╚██╔╝██║██╔══██╗██╔══╝  ██╔══██╗╚════██║
# ██║ ╚═╝ ██║███████╗██║ ╚═╝ ██║██████╔╝███████╗██║  ██║███████║
# ╚═╝     ╚═╝╚══════╝╚═╝     ╚═╝╚═════╝ ╚══════╝╚═╝  ╚═╝╚══════╝
##################################################################################################################
	public function members()
	{
		$members = User::where('role_id','!=',10)->orderBy('username','asc')->get();
		return view('frontend.members', compact('members'));
	}


##################################################################################################################
# ████████╗███████╗███████╗████████╗
# ╚══██╔══╝██╔════╝██╔════╝╚══██╔══╝
#    ██║   █████╗  ███████╗   ██║   
#    ██║   ██╔══╝  ╚════██║   ██║   
#    ██║   ███████╗███████║   ██║   
#    ╚═╝   ╚══════╝╚══════╝   ╚═╝   
##################################################################################################################
	public function test()
	{
		return view('test');
	}



}
<file_sep><?php

use Illuminate\Database\Seeder;

class WoodprojectsTableSeeder extends Seeder
{

    /**
     * Auto generated seed file
     *
     * @return void
     */
    public function run()
    {
        

        \DB::table('woodprojects')->delete();
        
        \DB::table('woodprojects')->insert(array (
            0 => 
            array (
                'id' => 1,
                'category_id' => 8,
                'name' => 'Storage Bench',
                'description' => 'Storage Bench',
                'main_image' => 'bench1_1518614756.jpg',
                'views' => 0,
                'time_invested' => 15,
                'price' => '65',
                'wood_specie_id' => '47',
                'wood_type_id' => '14',
                'width' => '38',
                'depth' => '20',
                'height' => '24',
                'stain_type_id' => NULL,
                'stain_color_id' => NULL,
                'stain_sheen_id' => NULL,
                'finish_type_id' => '32',
                'finish_sheen_id' => NULL,
                'completed_at' => '2018-02-02 00:00:00',
                'weight' => NULL,
                'created_at' => '2018-02-14 08:25:56',
                'updated_at' => '2018-02-14 08:25:56',
            ),
            1 => 
            array (
                'id' => 2,
                'category_id' => 8,
                'name' => 'Hall Table',
                'description' => 'Hall Table',
                'main_image' => 'hall-table_1518615064.jpg',
                'views' => 0,
                'time_invested' => 12,
                'price' => '50',
                'wood_specie_id' => '47',
                'wood_type_id' => '14',
                'width' => '36',
                'depth' => '20',
                'height' => '30',
                'stain_type_id' => NULL,
                'stain_color_id' => NULL,
                'stain_sheen_id' => NULL,
                'finish_type_id' => '32',
                'finish_sheen_id' => '53',
                'completed_at' => '2018-02-02 00:00:00',
                'weight' => NULL,
                'created_at' => '2018-02-14 08:31:04',
                'updated_at' => '2018-02-14 08:31:04',
            ),
            2 => 
            array (
                'id' => 3,
                'category_id' => 51,
                'name' => 'Candle Box 1',
                'description' => 'Light Brown Candle Box',
                'main_image' => 'candle_box_1_1518615146.jpg',
                'views' => 0,
                'time_invested' => 2,
                'price' => '5',
                'wood_specie_id' => '48',
                'wood_type_id' => '14',
                'width' => '12',
                'depth' => '5',
                'height' => '4',
                'stain_type_id' => NULL,
                'stain_color_id' => NULL,
                'stain_sheen_id' => NULL,
                'finish_type_id' => '32',
                'finish_sheen_id' => '53',
                'completed_at' => '2018-02-02 00:00:00',
                'weight' => NULL,
                'created_at' => '2018-02-14 08:32:26',
                'updated_at' => '2018-02-14 08:34:21',
            ),
            3 => 
            array (
                'id' => 4,
                'category_id' => 51,
                'name' => '<NAME>',
                'description' => 'Dark Brown Candle Box',
                'main_image' => 'candle_box_2_1518615228.jpg',
                'views' => 0,
                'time_invested' => 2,
                'price' => '10',
                'wood_specie_id' => '47',
                'wood_type_id' => '14',
                'width' => '12',
                'depth' => '5',
                'height' => '4',
                'stain_type_id' => '17',
                'stain_color_id' => NULL,
                'stain_sheen_id' => '28',
                'finish_type_id' => '32',
                'finish_sheen_id' => '53',
                'completed_at' => '2018-02-02 00:00:00',
                'weight' => NULL,
                'created_at' => '2018-02-14 08:33:49',
                'updated_at' => '2018-02-14 08:33:49',
            ),
            4 => 
            array (
                'id' => 5,
                'category_id' => 51,
                'name' => 'Candle Holder 1',
                'description' => 'Candle Holder 1',
                'main_image' => 'candle_holder_1_1518615425.jpg',
                'views' => 0,
                'time_invested' => 3,
                'price' => '15',
                'wood_specie_id' => '47',
                'wood_type_id' => '14',
                'width' => '7',
                'depth' => '5',
                'height' => '14',
                'stain_type_id' => NULL,
                'stain_color_id' => NULL,
                'stain_sheen_id' => NULL,
                'finish_type_id' => '32',
                'finish_sheen_id' => '53',
                'completed_at' => '2018-02-02 00:00:00',
                'weight' => NULL,
                'created_at' => '2018-02-14 08:37:05',
                'updated_at' => '2018-02-14 08:37:05',
            ),
            5 => 
            array (
                'id' => 6,
                'category_id' => 51,
                'name' => 'Candle Holder 2',
                'description' => 'Candle Holder 2',
                'main_image' => 'candle_holder_2_1518615485.jpg',
                'views' => 0,
                'time_invested' => 3,
                'price' => '16',
                'wood_specie_id' => '12',
                'wood_type_id' => '14',
                'width' => '7',
                'depth' => '5',
                'height' => '14',
                'stain_type_id' => '17',
                'stain_color_id' => NULL,
                'stain_sheen_id' => '28',
                'finish_type_id' => '32',
                'finish_sheen_id' => '53',
                'completed_at' => '2018-02-02 00:00:00',
                'weight' => NULL,
                'created_at' => '2018-02-14 08:38:05',
                'updated_at' => '2018-02-14 08:38:05',
            ),
            6 => 
            array (
                'id' => 7,
                'category_id' => 50,
                'name' => 'Small Chalkboard',
                'description' => 'Small Chalkboard',
                'main_image' => 'chalkboard_1518615569.jpg',
                'views' => 0,
                'time_invested' => 5,
                'price' => '25',
                'wood_specie_id' => '48',
                'wood_type_id' => '14',
                'width' => '25',
                'depth' => '3',
                'height' => '25',
                'stain_type_id' => '17',
                'stain_color_id' => '11',
                'stain_sheen_id' => '28',
                'finish_type_id' => '34',
                'finish_sheen_id' => '53',
                'completed_at' => '2018-02-02 00:00:00',
                'weight' => NULL,
                'created_at' => '2018-02-14 08:39:29',
                'updated_at' => '2018-02-14 08:39:29',
            ),
            7 => 
            array (
                'id' => 8,
                'category_id' => 51,
                'name' => 'Mirror',
                'description' => 'Mirror made from reclaimed window',
                'main_image' => 'mirror_1518615642.jpg',
                'views' => 0,
                'time_invested' => 12,
                'price' => '40',
                'wood_specie_id' => '12',
                'wood_type_id' => '14',
                'width' => '23',
                'depth' => '2',
                'height' => '24',
                'stain_type_id' => NULL,
                'stain_color_id' => NULL,
                'stain_sheen_id' => NULL,
                'finish_type_id' => '32',
                'finish_sheen_id' => '53',
                'completed_at' => '2018-02-02 00:00:00',
                'weight' => NULL,
                'created_at' => '2018-02-14 08:40:42',
                'updated_at' => '2018-02-14 08:40:42',
            ),
            8 => 
            array (
                'id' => 9,
                'category_id' => 9,
                'name' => 'Corner Shelf',
                'description' => 'Corner Shelf',
                'main_image' => 'corner_shelf_1518615745.jpg',
                'views' => 0,
                'time_invested' => 4,
                'price' => NULL,
                'wood_specie_id' => '12',
                'wood_type_id' => '14',
                'width' => '6',
                'depth' => '6',
                'height' => '60',
                'stain_type_id' => '17',
                'stain_color_id' => '10',
                'stain_sheen_id' => '28',
                'finish_type_id' => '32',
                'finish_sheen_id' => '53',
                'completed_at' => '2018-02-02 00:00:00',
                'weight' => NULL,
                'created_at' => '2018-02-14 08:42:25',
                'updated_at' => '2018-02-14 08:42:25',
            ),
            9 => 
            array (
                'id' => 10,
                'category_id' => 52,
                'name' => 'Wine Rack',
                'description' => 'Wine Rack can hold 8 bottles',
                'main_image' => 'wine_rack_1518615827.jpg',
                'views' => 0,
                'time_invested' => 4,
                'price' => NULL,
                'wood_specie_id' => '12',
                'wood_type_id' => '14',
                'width' => '8',
                'depth' => '7',
                'height' => '53',
                'stain_type_id' => NULL,
                'stain_color_id' => NULL,
                'stain_sheen_id' => NULL,
                'finish_type_id' => NULL,
                'finish_sheen_id' => NULL,
                'completed_at' => '2018-02-02 00:00:00',
                'weight' => NULL,
                'created_at' => '2018-02-14 08:43:47',
                'updated_at' => '2018-02-14 08:44:10',
            ),
        ));
        
        
    }
}<file_sep><?php
 
namespace App\Classes;

class ZeroOneDarts {

   function playerBestScore($player) {
      //dd($player);
      $val = DB::table('dartscores')
         ->where('game_id', $player->dartgame_id)
         ->where('team_id', $player->team_id)
         ->where('user_id', $player->id)
         ->max('score');

      if($val == 0)
      {
         return 'N/A';
      }

      return $val;
   }

}<file_sep><?php

function checkACL($acl) {
	if(Auth::check()) {
		if ($acl == 'guest') {
			if (Auth::user()->role_id <= 80) {
				return true;
			}
		} elseif ($acl == 'user') {
			if (Auth::user()->role_id <= 70) {
				return true;
			}
		// } elseif ($acl == 'author_posts') {
		// 	if (Auth::user()->role_id <= 61) {
		// 		return true;
		// 	}
		} elseif ($acl == 'author') {
			if (Auth::user()->role_id <= 60) {
				return true;
			}
		} elseif ($acl == 'timeTrack') {
			if (Auth::user()->role_id <= 55) {
				return true;
			}
		} elseif ($acl == 'editor') {
			if (Auth::user()->role_id <= 50) {
				return true;
			}
		} elseif ($acl == 'publisher') {
			if (Auth::user()->role_id <= 40) {
				return true;
			}
		} elseif ($acl == 'manager') {
			if (Auth::user()->role_id <= 30) {
				return true;
			}
		} elseif ($acl == 'admin') {
			if (Auth::user()->role_id <= 20) {
				return true;
			}
		} elseif ($acl == 'superadmin') {
			if (Auth::user()->role_id <= 10) {
				return true;
			}
		}
	}
}


function checkOwner($model) {
	if(Auth::check()) {
		if($model->user_id == Auth::user()->id) {
			//return 'checkOwner';
			return true;
		}
	}
}


function checkPerm($user_id) {
	// check if specific user can access specific page/module
}


function getClientIP(){
	return $_SERVER["REMOTE_ADDR"];
}



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ██████╗  █████╗ ██████╗ ████████╗███████╗
// ██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██╔════╝
// ██║  ██║███████║██████╔╝   ██║   ███████╗
// ██║  ██║██╔══██║██╔══██╗   ██║   ╚════██║
// ██████╔╝██║  ██║██║  ██║   ██║   ███████║
// ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝   ╚═╝   ╚══════╝
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function zeroOnePlayerBestScore($player) {
	//dd($player);
	$val = DB::table('dartscores')
		->where('game_id', $player->dartgame_id)
		->where('team_id', $player->team_id)
		->where('user_id', $player->id)
		->max('score');

	if($val == 0)
	{
		return 'N/A';
	}

	return $val;
}


function zeroOnePlayerScoreAvg($player) {
	$shots = DB::table('dartscores')
		->where('game_id', $player->dartgame_id)
		->where('team_id', $player->team_id)
		->where('user_id', $player->id)
		->count();
	
	if($shots == 0)
	{
		return 'N/A';
	}

	$totaluserscore = DB::table('dartscores')
		->where('game_id', $player->dartgame_id)
		->where('team_id', $player->team_id)
		->where('user_id', $player->id)
		->sum('score');

	$val = $totaluserscore / $shots;

	return number_format($val, 2);
}


function zeroOnePlayerDartAvg($player) {
	$shots = DB::table('dartscores')
		->where('game_id', $player->dartgame_id)
		->where('team_id', $player->team_id)
		->where('user_id', $player->id)
		->count();

	if($shots == 0) { return 'N/A'; }

	$totaluserscore = DB::table('dartscores')
		->where('game_id', $player->dartgame_id)
		->where('team_id', $player->team_id)
		->where('user_id', $player->id)
		->sum('score');

	$val = ($totaluserscore / $shots) / 3;

	return number_format($val, 2);
}


function zeroOneTeamBestScore($game, $team) {
	$val = DB::table('dartscores')
		->join('dartgame_user', 'dartscores.user_id', '=', 'dartgame_user.user_id')
		->where('game_id', $game->id)
		->where('dartscores.team_id', $team)
		->max('score');

	if($val == 0) { return 'N/A'; }

	return $val;
}


function zeroOneTeamBestScoreBy($game, $team) {
	$v1 = DB::table('dartscores')
		->where('game_id', $game->id)
		->where('team_id', $team)
		->orderby('score','desc')
		->first();

	if(!$v1) { return 'N/A'; }

	$val = DB::table('Users')
		->join('profiles', 'users.id', '=', 'profiles.user_id')
		->where('users.id', '=', $v1->user_id)
		->first();

	return $val->first_name;
}

	
function zeroOneTeamScores($game, $team) {
	$t = DB::table('dartscores')
		->join('users', 'dartscores.user_id', '=', 'users.id')
		->join('profiles', 'dartscores.user_id', '=', 'profiles.user_id')
		->where('game_id', $game->id)
		->where('team_id', $team)
		->orderBy('dartscores.id','desc')
		->get();

	return $t;
}


function zeroOneTeamPlayers($game, $team) {
	$teamPlayers = DB::table('dartgame_user')
		->join('users', 'dartgame_user.user_id', '=', 'users.id')
		->join('profiles', 'dartgame_user.user_id', '=', 'profiles.user_id')
		->where('dartgame_id', $game->id)
		->where('team_id', $team)
		->orderBy('dartgame_user.id', 'asc')
		->get();

	return $teamPlayers;
}


function zeroOnePlayers($game) {
	$teamPlayers = DB::table('dartgame_user')
		->join('users', 'dartgame_user.user_id', '=', 'users.id')
		->join('profiles', 'dartgame_user.user_id', '=', 'profiles.user_id')
		->where('dartgame_id', $game->id)
		->orderBy('dartgame_user.id', 'asc')
		->get();
	//dd($teamPlayers);
	return $teamPlayers;
}


function zeroOneAllPlayers($game) {
	$allPlayers = DB::table('dartgame_user')
		->join('users', 'dartgame_user.user_id', '=', 'users.id')
		->join('profiles', 'dartgame_user.user_id', '=', 'profiles.user_id')
		->where('dartgame_id', $game->id)
		->orderBy('profiles.first_name', 'asc')
		->get();

	return $allPlayers;
}


function zeroOneGameWinner($game) {
	if ($winner = DB::table('dartscores')
		->where('game_id', $game->id)
		->where('remaining', 0)
		->first())
	{
		return 'Team ' . $winner->team_id;
	}
}


function zeroOneLastShot($game) {
	
	$last = DB::table('dartscores')
		//->join('users', 'dartscores.user_id', '=', 'users.id')
		->join('dartgame_user', 'dartscores.user_id', '=', 'dartgame_user.user_id')
		->where('game_id', $game->id)
		->latest('dartscores.id')
		->first();
		//dd($last);
	
	if($last){
	// 	// Return last player to shoot
		//echo "LAST : " . $last->user_id . "<br />";
		//dd($last->shooting_order);
		return $last->shooting_order;
	 	
	}
}


function zeroOneNextShot($game) {
	$totalPlayers = DB::table('dartgame_user')
		->where('dartgame_id', $game->id)
		->orderBy('shooting_order', 'asc')
		->count();
		//echo '<br />Total Players : ' . ($totalPlayers) . '<br />'; 

	// if(lastShot($game)) {
	if (zeroOneLastShot($game)) {
		//echo 'Last Shot : ' . zeroOneLastShot($game) . "<br />";
		$i = zeroOneLastShot($game) + 1;
		// $i = $i = zeroOneLastShot($game);
		// $i = $i + 1;

		// echo 'Next Shot :' . $i;
		
		if($i > $totalPlayers) {
			return 1;
		}

		return $i;

	} else {
		// No one has shot yet, so set shooting order to 1
		return 1;
	}
}











//
// Individual Player Games
//

	// function zeroOnePlayerLastShot($game) {
		
	// 	$last = DB::table('dartscores')
	// 		->join('users', 'dartscores.user_id', '=', 'users.id')
	// 		->join('dartgame_user', 'dartscores.user_id', '=', 'dartgame_user.user_id')
	// 		->where('game_id', $game->id)
	// 		->latest('dartscores.id')
	// 		->first();
	// 		//dd($last);
		
	// 	if($last){
	// 	// 	// Return last player to shoot
	// 		//echo "LAST : " . $last->user_id . "<br />";
	// 		//dd('last shot:'. $last->shooting_order);
	// 		return $last->shooting_order;
		 	
	// 	}
	// }


	// function zeroOnePlayerNextShot($game) {
	// 	//dd($game->id);
	// 	$totalPlayers = DB::table('dartgame_user')
	// 		->where('dartgame_id', $game->id)
	// 		->where('dartgame_user.shooting_order', zeroOnePlayerLastShot($game))
	// 		->orderBy('shooting_order', 'asc')
	// 		->count();
	// 	 echo '<br />Total Players : ' . ($totalPlayers) . '<br />'; 

	// 	if (zeroOnePlayerLastShot($game)) {
	// 		//dd('PLS is set'.$game->shooting_order);
	// 		echo "LAST SHOT:" . (zeroOnePlayerLastShot($game)) . "<br />";

	// 		$i = zeroOnePlayerLastShot($game) + 1;
	// 		//dd('LAST SHOT:' . $i);
			
	// 		if($i > $totalPlayers) {
	// 			return 1;
	// 		}

	// 		return $i;

	// 	} else {
	// 		// No one has shot yet, so set shooting order to 1
	// 		return 1;
	// 		//echo 'Next Shot::: 1';

	// 	}
	// }





	function zeroOnePlayerScore($game, $player) {
		$t = DB::table('dartscores')
			->join('users', 'dartscores.user_id', '=', 'users.id')
			->join('profiles', 'dartscores.user_id', '=', 'profiles.user_id')
			->where('game_id', $game)
			->where('dartscores.user_id', $player)
			->orderBy('dartscores.id','desc')
			->get();
		//dd($t);
		return $t;
	}<file_sep><?php

namespace App\Http\Controllers\Backend;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Gallery;
use Auth;
use Session;
use Validator;
use Intervention\Image\Facades\Image;

class GalleryController extends Controller
{

##################################################################################################################
#  ██████╗ ██████╗ ███╗   ██╗███████╗████████╗██████╗ ██╗   ██╗ ██████╗████████╗
# ██╔════╝██╔═══██╗████╗  ██║██╔════╝╚══██╔══╝██╔══██╗██║   ██║██╔════╝╚══██╔══╝
# ██║     ██║   ██║██╔██╗ ██║███████╗   ██║   ██████╔╝██║   ██║██║        ██║   
# ██║     ██║   ██║██║╚██╗██║╚════██║   ██║   ██╔══██╗██║   ██║██║        ██║   
# ╚██████╗╚██████╔╝██║ ╚████║███████║   ██║   ██║  ██║╚██████╔╝╚██████╗   ██║   
#  ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝  ╚═════╝   ╚═╝   
##################################################################################################################
	public function __construct() {
		$this->middleware('auth');
	}


##################################################################################################################
# ██╗███╗   ██╗██████╗ ███████╗██╗  ██╗
# ██║████╗  ██║██╔══██╗██╔════╝╚██╗██╔╝
# ██║██╔██╗ ██║██║  ██║█████╗   ╚███╔╝ 
# ██║██║╚██╗██║██║  ██║██╔══╝   ██╔██╗ 
# ██║██║ ╚████║██████╔╝███████╗██╔╝ ██╗
# ╚═╝╚═╝  ╚═══╝╚═════╝ ╚══════╝╚═╝  ╚═╝
// Display a list of resources
##################################################################################################################
	public function viewGalleryList()
	{
		$galleries = Gallery::All();
		return view('backend.galleries.index', compact('galleries'));
	}


##################################################################################################################
# ███████╗████████╗ ██████╗ ██████╗ ███████╗
# ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
# ███████╗   ██║   ██║   ██║██████╔╝█████╗  
# ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝  
# ███████║   ██║   ╚██████╔╝██║  ██║███████╗
# ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
// Store a newly created resource in storage
##################################################################################################################
	public function saveGallery(Request $request)
	{
		// Validate the request thorugh the validation rules
		$validator = Validator::make($request->all(), [
			'gallery_name' => 'required|min:5'
		]);

		// Validation fails
		if ($validator->fails()) {
			return redirect('backend.gallery.list')
				->withErrors($validator)
				->withInput();
		}

		$gallery = new Gallery;
			$gallery->name = $request->input('gallery_name');
			$gallery->created_by = Auth::user()->id;
			$gallery->published = 1;
		$gallery->save();

		return redirect()->back();
	}


##################################################################################################################
# ███████╗██████╗ ██╗████████╗
# ██╔════╝██╔══██╗██║╚══██╔══╝
# █████╗  ██║  ██║██║   ██║   
# ██╔══╝  ██║  ██║██║   ██║   
# ███████╗██████╔╝██║   ██║   
# ╚══════╝╚═════╝ ╚═╝   ╚═╝   
// Show the form for editing the specified resource
##################################################################################################################
	public function editGallery($id)
	{
		$gallery = Gallery::find($id);

		return view('backend.galleries.edit', compact('gallery'));
	}


##################################################################################################################
# ██╗   ██╗██████╗ ██████╗  █████╗ ████████╗███████╗
# ██║   ██║██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██╔════╝
# ██║   ██║██████╔╝██║  ██║███████║   ██║   █████╗  
# ██║   ██║██╔═══╝ ██║  ██║██╔══██║   ██║   ██╔══╝  
# ╚██████╔╝██║     ██████╔╝██║  ██║   ██║   ███████╗
#  ╚═════╝ ╚═╝     ╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚══════╝
// UPDATE :: Update the specified resource in storage
##################################################################################################################
	// public function updateGallery(UpdateGalleryRequest $request, $id)
	public function updateGallery(Request $request, $id)
	{
		
		// if(!checkACL('author')) {
		//     return view('errors.403');
		// }

		//dd($request->ref);

		$gallery = Gallery::findOrFail($id);
			$gallery->name = $request->name;
		$gallery->save();
		
		// Save entry to log file using built-in Monolog
		//Log::info(Auth::user()->username . " (" . Auth::user()->id . ") UPDATED article (" . $article->id . ")\r\n",
		//    [json_decode($article, true)]
		//);

		Session::flash('success','The gallery has been updated successfully.');
		return redirect()->route('backend.gallery.list');
	}


##################################################################################################################
# ███████╗██╗  ██╗ ██████╗ ██╗    ██╗
# ██╔════╝██║  ██║██╔═══██╗██║    ██║
# ███████╗███████║██║   ██║██║ █╗ ██║
# ╚════██║██╔══██║██║   ██║██║███╗██║
# ███████║██║  ██║╚██████╔╝╚███╔███╔╝
# ╚══════╝╚═╝  ╚═╝ ╚═════╝  ╚══╝╚══╝ 
// Display the specified resource
##################################################################################################################
	public function viewGalleryPics($id)
	{
		$gallery = Gallery::findOrFail($id);

		return view('backend.galleries.show', compact('gallery'));
	}


##################################################################################################################
# ██╗███╗   ███╗ █████╗  ██████╗ ███████╗    ██╗   ██╗██████╗ ██╗      ██████╗  █████╗ ██████╗ 
# ██║████╗ ████║██╔══██╗██╔════╝ ██╔════╝    ██║   ██║██╔══██╗██║     ██╔═══██╗██╔══██╗██╔══██╗
# ██║██╔████╔██║███████║██║  ███╗█████╗      ██║   ██║██████╔╝██║     ██║   ██║███████║██║  ██║
# ██║██║╚██╔╝██║██╔══██║██║   ██║██╔══╝      ██║   ██║██╔═══╝ ██║     ██║   ██║██╔══██║██║  ██║
# ██║██║ ╚═╝ ██║██║  ██║╚██████╔╝███████╗    ╚██████╔╝██║     ███████╗╚██████╔╝██║  ██║██████╔╝
# ╚═╝╚═╝     ╚═╝╚═╝  ╚═╝ ╚═════╝ ╚══════╝     ╚═════╝ ╚═╝     ╚══════╝ ╚═════╝ ╚═╝  ╚═╝╚═════╝ 
##################################################################################################################
	public function doImageUpload(Request $request)
	{
		// get the file from the post request
		$file = $request->file('file');

		// set filename
		$filename = uniqid() . $file->getClientOriginalName();

		// Check if Gallery/Images folders exists
		if (!file_exists('_gallery/images')) {
			mkdir('_gallery/images', 0777, true);
		}

		// move the file to the correct location
		$file->move('_gallery/images', $filename);

		// Check if Thumbs folder exists under Images
		if (!file_exists('_gallery/images/thumbs')) {
			mkdir('_gallery/images/thumbs', 0777, true);
		}

		// Create thumbnail
		$thumb = Image::make('_gallery/images/' . $filename)->resize(240,160)->save('_gallery/images/thumbs/' . $filename, 60);

		// save image details in database
		$gallery = Gallery::find($request->input('gallery_id'));
		$image = $gallery->images()->create([
			'gallery_id' => $request->input('gallery_id'),
			'file_name' => $filename,
			'file_size' => $file->getClientSize(),
			'file_mime' => $file->getClientMimeType(),
			'file_path' => '_gallery/images/' . $filename,
			'created_by' => Auth::user()->id,
		]);

		return $image;
	}


##################################################################################################################
# ██████╗ ███████╗███████╗████████╗██████╗  ██████╗ ██╗   ██╗
# ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔══██╗██╔═══██╗╚██╗ ██╔╝
# ██║  ██║█████╗  ███████╗   ██║   ██████╔╝██║   ██║ ╚████╔╝ 
# ██║  ██║██╔══╝  ╚════██║   ██║   ██╔══██╗██║   ██║  ╚██╔╝  
# ██████╔╝███████╗███████║   ██║   ██║  ██║╚██████╔╝   ██║   
# ╚═════╝ ╚══════╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝    ╚═╝   
// Remove the specified resource from storage
// Used in the index page and trashAll action to soft delete multiple records
##################################################################################################################
	public function deleteGallery($id)
	{
		// Load the gallery
		$currentGallery = Gallery::findOrFail($id);

		// check owenership
		if($currentGallery->created_by != Auth::user()->id) {
			abort('403', 'You are not allowed to delete this gallery!');
		}

		// get the images
		$images = $currentGallery->images();

		// delete the images
		foreach($currentGallery->images as $image) {
			unlink(public_path($image->file_path));
			unlink(public_path('_gallery/images/thumbs/' . $image->file_name));
		}

		// Delete all image rows from the table
		$images->delete();

		// Delete the gallery
		$currentGallery->delete();

		return redirect()->back();
	}

}
<file_sep><?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Auth;

class Role extends Model
{
	public function users()
   {
      return $this->hasMany('App\User');
   }

   public function scopeNewRoles($query)
   {
      return $query
         ->where('created_at', '>=' , Auth::user()->last_login_date)
         //->where('user_id', '=', Auth::user()->id)
         ->orderBy('name','DESC');
   }
}
<file_sep><?php

namespace App\Http\Controllers\Backend;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;
//use Charts;
use App\Album;
use App\Article;
use App\Category;
use App\Comment;
use App\Module;
use App\Post;
use App\Recipe;
use App\Role;
use App\User;
use App\WoodProject;

class dashboardController extends Controller
{

##################################################################################################################
#  ██████╗ ██████╗ ███╗   ██╗███████╗████████╗██████╗ ██╗   ██╗ ██████╗████████╗
# ██╔════╝██╔═══██╗████╗  ██║██╔════╝╚══██╔══╝██╔══██╗██║   ██║██╔════╝╚══██╔══╝
# ██║     ██║   ██║██╔██╗ ██║███████╗   ██║   ██████╔╝██║   ██║██║        ██║   
# ██║     ██║   ██║██║╚██╗██║╚════██║   ██║   ██╔══██╗██║   ██║██║        ██║   
# ╚██████╗╚██████╔╝██║ ╚████║███████║   ██║   ██║  ██║╚██████╔╝╚██████╗   ██║   
#  ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝  ╚═════╝   ╚═╝   
##################################################################################################################
	public function __construct() {
		$this->middleware('auth');
		//Log::useFiles(storage_path().'/logs/articles.log');
		//Log::useFiles(storage_path().'/logs/audits.log');
	}


##################################################################################################################
# ██╗███╗   ██╗██████╗ ███████╗██╗  ██╗
# ██║████╗  ██║██╔══██╗██╔════╝╚██╗██╔╝
# ██║██╔██╗ ██║██║  ██║█████╗   ╚███╔╝ 
# ██║██║╚██╗██║██║  ██║██╔══╝   ██╔██╗ 
# ██║██║ ╚████║██████╔╝███████╗██╔╝ ██╗
# ╚═╝╚═╝  ╚═══╝╚═════╝ ╚══════╝╚═╝  ╚═╝
// Display a list of resources
##################################################################################################################
	public function index()
	{
		$roles = Role::with('users')->where('id', '<', 80)->get();
		// $authors = User::where('role_id', '=' , )
		// $sadmins = User::with('role')->where('role_id','=',10)->get();
		// $admins = User::with('role')->where('role_id','=',20)->get();
		// $managers = User::with('role')->where('role_id','=',30)->get();
		// $publishers = User::with('role')->where('role_id','=',40)->get();
		// $editors = User::with('role')->where('role_id','=',50)->get();
		// $timetrackers = User::with('role')->where('role_id','=',55)->get();
		// $authors = User::with('role')->where('role_id','=',60)->get();
		// $users = User::with('role')->where('role_id','=',70)->get();
		// $users = User::with('role')->get();
		//dd($authors);

		$albums = Album::where('created_at', '>=' , Auth::user()->last_login_date)->get();
		$articles = Article::with('user')->where('created_at', '>=' , Auth::user()->last_login_date)->get();
		$categories = Category::where('created_at', '>=' , Auth::user()->last_login_date)->get();
		$comments = Comment::where('created_at', '>=' , Auth::user()->last_login_date)->get();
		$modules = Module::where('created_at', '>=' , Auth::user()->last_login_date)->get();
		$posts = Post::with('user')->where('created_at', '>=' , Auth::user()->last_login_date)->get();
		$recipes = Recipe::with('user')->where('created_at', '>=' , Auth::user()->last_login_date)->get();
		$roles1 = Role::where('created_at', '>=' , Auth::user()->last_login_date)->get();
		$users = User::where('created_at', '>=' , Auth::user()->last_login_date)->get();
		$woodProjects = WoodProject::where('created_at', '>=' , Auth::user()->last_login_date)->get();

		// return view('backend.dashboard', compact('roles','sadmins', 'admins','managers','publishers','editors','timetrackers','authors','users'));
		return view('backend.dashboard', compact('albums','articles','categories','comments','modules','posts','recipes','roles','roles1','users','woodProjects'));
		
	}


##################################################################################################################
# ██████╗  ██████╗ ███████╗████████╗███████╗
# ██╔══██╗██╔═══██╗██╔════╝╚══██╔══╝██╔════╝
# ██████╔╝██║   ██║███████╗   ██║   ███████╗
# ██╔═══╝ ██║   ██║╚════██║   ██║   ╚════██║
# ██║     ╚██████╔╝███████║   ██║   ███████║
# ╚═╝      ╚═════╝ ╚══════╝   ╚═╝   ╚══════╝
##################################################################################################################
	public function posts()
	{
		return view('backend.posts.index');
	}


##################################################################################################################
# ██╗████████╗███████╗███╗   ███╗███████╗
# ██║╚══██╔══╝██╔════╝████╗ ████║██╔════╝
# ██║   ██║   █████╗  ██╔████╔██║███████╗
# ██║   ██║   ██╔══╝  ██║╚██╔╝██║╚════██║
# ██║   ██║   ███████╗██║ ╚═╝ ██║███████║
# ╚═╝   ╚═╝   ╚══════╝╚═╝     ╚═╝╚══════╝
##################################################################################################################
	public function items()
	{
		return view('backend.items.index');
	}


##################################################################################################################
# ██████╗ ███████╗ ██████╗██╗██████╗ ███████╗███████╗
# ██╔══██╗██╔════╝██╔════╝██║██╔══██╗██╔════╝██╔════╝
# ██████╔╝█████╗  ██║     ██║██████╔╝█████╗  ███████╗
# ██╔══██╗██╔══╝  ██║     ██║██╔═══╝ ██╔══╝  ╚════██║
# ██║  ██║███████╗╚██████╗██║██║     ███████╗███████║
# ╚═╝  ╚═╝╚══════╝ ╚═════╝╚═╝╚═╝     ╚══════╝╚══════╝
##################################################################################################################
	public function recipes()
	{
		return view('backend.recipes.index');
	}


##################################################################################################################
# ██████╗ ██████╗  ██████╗ ██████╗ ██╗   ██╗ ██████╗████████╗███████╗
# ██╔══██╗██╔══██╗██╔═══██╗██╔══██╗██║   ██║██╔════╝╚══██╔══╝██╔════╝
# ██████╔╝██████╔╝██║   ██║██║  ██║██║   ██║██║        ██║   ███████╗
# ██╔═══╝ ██╔══██╗██║   ██║██║  ██║██║   ██║██║        ██║   ╚════██║
# ██║     ██║  ██║╚██████╔╝██████╔╝╚██████╔╝╚██████╗   ██║   ███████║
# ╚═╝     ╚═╝  ╚═╝ ╚═════╝ ╚═════╝  ╚═════╝  ╚═════╝   ╚═╝   ╚══════╝
##################################################################################################################
	public function products()
	{
		return view('backend.products.index');
	}





}<file_sep><?php

namespace App\Http\Controllers\Frontend;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use App\Article;
use App\Category;
use App\Comment;
use App\User;
use Carbon\Carbon;
use Auth;
use DB;
use Excel;
use Log;
use Session;

use App\Http\Requests\CreateArticleRequest;
use App\Http\Requests\UpdateArticleRequest;
use App\Http\Requests\CreateCommentRequest;

class ArticlesController extends Controller
{

##################################################################################################################
#  ██████╗ ██████╗ ███╗   ██╗███████╗████████╗██████╗ ██╗   ██╗ ██████╗████████╗
# ██╔════╝██╔═══██╗████╗  ██║██╔════╝╚══██╔══╝██╔══██╗██║   ██║██╔════╝╚══██╔══╝
# ██║     ██║   ██║██╔██╗ ██║███████╗   ██║   ██████╔╝██║   ██║██║        ██║   
# ██║     ██║   ██║██║╚██╗██║╚════██║   ██║   ██╔══██╗██║   ██║██║        ██║   
# ╚██████╗╚██████╔╝██║ ╚████║███████║   ██║   ██║  ██║╚██████╔╝╚██████╗   ██║   
#  ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝  ╚═════╝   ╚═╝   
##################################################################################################################
	public function __construct() {
		// only allow authenticated users to access these pages
		//$this->middleware('auth', ['except'=>['index','show']]);
		// changing auth to guest would only allow guests to access these pages
		// you can also restrict the actions by adding ['except' => 'name_of_action'] at the end
		//$this->middleware('auth')->except('frontArticles', 'show');

		//Log::useFiles(storage_path().'/logs/articles.log');
		//Log::useFiles(storage_path().'/logs/audits.log');
	}


##################################################################################################################
#  █████╗ ██████╗  ██████╗██╗  ██╗██╗██╗   ██╗███████╗
# ██╔══██╗██╔══██╗██╔════╝██║  ██║██║██║   ██║██╔════╝
# ███████║██████╔╝██║     ███████║██║██║   ██║█████╗  
# ██╔══██║██╔══██╗██║     ██╔══██║██║╚██╗ ██╔╝██╔══╝  
# ██║  ██║██║  ██║╚██████╗██║  ██║██║ ╚████╔╝ ███████╗
# ╚═╝  ╚═╝╚═╝  ╚═╝ ╚═════╝╚═╝  ╚═╝╚═╝  ╚═══╝  ╚══════╝
# Display the archived resources
##################################################################################################################
	public function archive($year, $month)
	{

		// Get list of articles by year and month
		$articlelinks = DB::table('articles')
			->select(DB::raw('YEAR(created_at) year, MONTH(created_at) month, MONTHNAME(created_at) month_name, COUNT(*) article_count'))
			->where('published_at', '<=', Carbon::now())
			//->where('created_at', '<=', Carbon::now()->subMonth(3))
			->groupBy('year')
			->groupBy('month')
			->orderBy('year', 'desc')
			->orderBy('month', 'desc')
			->get();

		$archives = Article::with('user')->whereYear('created_at','=', $year)
			->whereMonth('created_at','=', $month)
			->where('published_at', '<=', Carbon::now())
			->get();

		// Save the URL in a varibale so it can be used in the blog.single page to redirect the user to the archives list page
		Session::flash('backUrl', \Request::fullUrl());

		return view('frontend.articles.archive', compact('archives','articlelinks'))->withYear($year)->withMonth($month);
	}


##################################################################################################################
# ██╗███╗   ██╗██████╗ ███████╗██╗  ██╗
# ██║████╗  ██║██╔══██╗██╔════╝╚██╗██╔╝
# ██║██╔██╗ ██║██║  ██║█████╗   ╚███╔╝ 
# ██║██║╚██╗██║██║  ██║██╔══╝   ██╔██╗ 
# ██║██║ ╚████║██████╔╝███████╗██╔╝ ██╗
# ╚═╝╚═╝  ╚═══╝╚═════╝ ╚══════╝╚═╝  ╚═╝
// Display a list of resources
##################################################################################################################
	public function index(Request $request, $key=null)
	{
		// if(!checkACL('guest')) {
		//     return view('errors.403');
		// }

		// Get list of articles by year and month
		$articlelinks = DB::table('articles')
			->select(DB::raw('YEAR(created_at) year, MONTH(created_at) month, MONTHNAME(created_at) month_name, COUNT(*) article_count'))
			->where('published_at', '<=', Carbon::now())
			//->where('created_at', '<=', Carbon::now()->subMonth(3))
			->groupBy('year')->groupBy('month')->orderBy('year', 'desc')->orderBy('month', 'desc')->get();

		//$alphas = range('A', 'Z');
		$alphas = DB::table('articles')
			->select(DB::raw('DISTINCT LEFT(title, 1) as letter'))
			->where('published_at','<', Carbon::Now())
			//->where('deleted_at', '=', Null)
			->orderBy('letter')
			->get();

		$letters = [];
		foreach($alphas as $alpha) {
			$letters[] = $alpha->letter;
		}

		// If $key value is passed
		if ($key) {
			$articles = Article::with('user','category')->published()
				->where('title', 'like', $key . '%')
				->orderBy('title', 'asc')
				->get();
			return view('frontend.articles.index', compact('articles','letters', 'articlelinks'));
		}

		// No $key value is passed
		$articles = Article::with('user','category')->published()->get();
		return view('frontend.articles.index', compact('articles','letters', 'articlelinks'));
	}


##################################################################################################################
# ██████╗ ██████╗ ██╗███╗   ██╗████████╗
# ██╔══██╗██╔══██╗██║████╗  ██║╚══██╔══╝
# ██████╔╝██████╔╝██║██╔██╗ ██║   ██║   
# ██╔═══╝ ██╔══██╗██║██║╚██╗██║   ██║   
# ██║     ██║  ██║██║██║ ╚████║   ██║   
# ╚═╝     ╚═╝  ╚═╝╚═╝╚═╝  ╚═══╝   ╚═╝   
##################################################################################################################
	public function print($id)
	{
		if(!checkACL('author')) {
			return view('errors.frontend.403');
		}

		$article = Article::find($id);

		// Save entry to log file using built-in Monolog
		// Log::info(Auth::user()->username . " (" . Auth::user()->id . ") PRINTED article (" . $article->id . ")\r\n", 
		// 	[json_decode($article, true)]
		// );

		return view('frontend.articles.print')->withArticle($article);
	}


##################################################################################################################
# ███████╗██╗  ██╗ ██████╗ ██╗    ██╗
# ██╔════╝██║  ██║██╔═══██╗██║    ██║
# ███████╗███████║██║   ██║██║ █╗ ██║
# ╚════██║██╔══██║██║   ██║██║███╗██║
# ███████║██║  ██║╚██████╔╝╚███╔███╔╝
# ╚══════╝╚═╝  ╚═╝ ╚═════╝  ╚══╝╚══╝ 
// Display the specified resource
##################################################################################################################
	public function show($id)
	{
		// if(!checkACL('guest')) {
		//     return view('errors.403');
		// }

		$article = Article::findOrFail($id);

		// get previous article id
		$previous = Article::published()->where('id', '<', $article->id)->max('id');

		// get next article id
		$next = Article::published()->where('id', '>', $article->id)->min('id');

		// Add 1 to views column
		DB::table('articles')->where('id','=',$article->id)->increment('views',1);

		// Get list of articles by year and month
		$articlelinks = DB::table('articles')
			->select(DB::raw('YEAR(created_at) year, MONTH(created_at) month, MONTHNAME(created_at) month_name, COUNT(*) article_count'))
			->where('published_at', '<=', Carbon::now())
			//->where('created_at', '<=', Carbon::now()->subMonth(3))
			->groupBy('year')
			->groupBy('month')
			->orderBy('year', 'desc')
			->orderBy('month', 'desc')
			->get();

		// Save entry to log file using built-in Monolog
		// if (Auth::check()) {
		//     Log::info(Auth::user()->username . " (" . Auth::user()->id . ") VIEWED article (" . $article->id . ")");
		// } else {
		//     Log::info('Guest viewed article (' . $article->id) . ')';
		// }

		return view('frontend.articles.show', compact('article','articlelinks','next','previous'));
	}


##################################################################################################################
# ███████╗████████╗ ██████╗ ██████╗ ███████╗     ██████╗ ██████╗ ███╗   ███╗███╗   ███╗███████╗███╗   ██╗████████╗
# ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝    ██╔════╝██╔═══██╗████╗ ████║████╗ ████║██╔════╝████╗  ██║╚══██╔══╝
# ███████╗   ██║   ██║   ██║██████╔╝█████╗      ██║     ██║   ██║██╔████╔██║██╔████╔██║█████╗  ██╔██╗ ██║   ██║   
# ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝      ██║     ██║   ██║██║╚██╔╝██║██║╚██╔╝██║██╔══╝  ██║╚██╗██║   ██║   
# ███████║   ██║   ╚██████╔╝██║  ██║███████╗    ╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ╚═╝ ██║███████╗██║ ╚████║   ██║   
# ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝     ╚═════╝ ╚═════╝ ╚═╝     ╚═╝╚═╝     ╚═╝╚══════╝╚═╝  ╚═══╝   ╚═╝   
##################################################################################################################
	public function storeComment(CreateCommentRequest $request, $id)
	{

		$article = Article::find($id);

		$comment = new Comment();
			$comment->user_id = Auth::user()->id;
			$comment->comment = $request->comment;
		$article->comments()->save($comment);

		// Save entry to log file using built-in Monolog
		// if (Auth::check()) {
		//     Log::info(Auth::user()->username . " (" . Auth::user()->id . ") commented on post (" . $post->id . ")\r\n", [json_decode($comment, true)]);
		// } else {
		//     Log::info(Request::ip() . " commented on post " . $post->id);
		// }

		Session::flash('success', 'Comment added succesfully.');
		return redirect()->route('articles.show', $article->id);
	}


}
<file_sep><?php

namespace App\Http\Controllers\Frontend;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

use App\Comment;
use App\Post;
use App\Http\Requests;
use DB;
use Session;
use Carbon\Carbon;
use Auth;
use Log;
use Redirect;

use App\Http\Requests\CreateCommentRequest;

class BlogController extends Controller
{

##################################################################################################################
#  ██████╗ ██████╗ ███╗   ██╗███████╗████████╗██████╗ ██╗   ██╗ ██████╗████████╗
# ██╔════╝██╔═══██╗████╗  ██║██╔════╝╚══██╔══╝██╔══██╗██║   ██║██╔════╝╚══██╔══╝
# ██║     ██║   ██║██╔██╗ ██║███████╗   ██║   ██████╔╝██║   ██║██║        ██║   
# ██║     ██║   ██║██║╚██╗██║╚════██║   ██║   ██╔══██╗██║   ██║██║        ██║   
# ╚██████╗╚██████╔╝██║ ╚████║███████║   ██║   ██║  ██║╚██████╔╝╚██████╗   ██║   
#  ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝  ╚═════╝   ╚═╝   
##################################################################################################################
	public function __construct() {
		//Log::useFiles(storage_path().'/logs/audits.log');
	}


##################################################################################################################
#  █████╗ ██████╗  ██████╗██╗  ██╗██╗██╗   ██╗███████╗
# ██╔══██╗██╔══██╗██╔════╝██║  ██║██║██║   ██║██╔════╝
# ███████║██████╔╝██║     ███████║██║██║   ██║█████╗  
# ██╔══██║██╔══██╗██║     ██╔══██║██║╚██╗ ██╔╝██╔══╝  
# ██║  ██║██║  ██║╚██████╗██║  ██║██║ ╚████╔╝ ███████╗
# ╚═╝  ╚═╝╚═╝  ╚═╝ ╚═════╝╚═╝  ╚═╝╚═╝  ╚═══╝  ╚══════╝
# Display the archived resources
##################################################################################################################
	public function archive($year, $month)
	{

		// Get list of posts by year and month
		$postlinks = DB::table('posts')
			->select(DB::raw('YEAR(created_at) year, MONTH(created_at) month, MONTHNAME(created_at) month_name, COUNT(*) post_count'))
			->where('published_at', '<=', Carbon::now())
			//->where('created_at', '<=', Carbon::now()->subMonth(3))
			->groupBy('year')
			->groupBy('month')
			->orderBy('year', 'desc')
			->orderBy('month', 'desc')
			->get();

		$archives = Post::published()->with('user')->whereYear('created_at','=', $year)
			->whereMonth('created_at','=', $month)
			->get();

		// Save the URL in a varibale so it can be used in the blog.single page to redirect the user to the archives list page
		Session::flash('backUrl', \Request::fullUrl());

		return view('frontend.blog.archive', compact('archives','postlinks'))->withYear($year)->withMonth($month);
	}


##################################################################################################################
# ██╗███╗   ██╗██████╗ ███████╗██╗  ██╗
# ██║████╗  ██║██╔══██╗██╔════╝╚██╗██╔╝
# ██║██╔██╗ ██║██║  ██║█████╗   ╚███╔╝ 
# ██║██║╚██╗██║██║  ██║██╔══╝   ██╔██╗ 
# ██║██║ ╚████║██████╔╝███████╗██╔╝ ██╗
# ╚═╝╚═╝  ╚═══╝╚═════╝ ╚══════╝╚═╝  ╚═╝
// Display a list of resources
##################################################################################################################
	public function getIndex()
	{
		// Save entry to log file using built-in Monolog
		// if(Auth::check()) {
		// 	Log::info(Auth::user()->username . " (" . Auth::user()->id . ") accessed :: Blog");
		// }else{
		// 	Log::info(getClientIP() . " accessed :: Blog");
		// }

		// $popularPost = Post::get()->sortByDesc('views')->take(1);
		//dd($popularPost);
		$posts = Post::published()->with('user')->orderBy('id','desc')->paginate(5);//->get();

		// Get list of posts by year and month
		$postlinks = DB::table('posts')
			->select(DB::raw('YEAR(created_at) year, MONTH(created_at) month, MONTHNAME(created_at) month_name, COUNT(*) post_count'))
			->where('published_at', '<=', Carbon::now())
			//->where('created_at', '<=', Carbon::now()->subMonth(3))
			->groupBy('year')
			->groupBy('month')
			->orderBy('year', 'desc')
			->orderBy('month', 'desc')
			->get();

		// return view ('frontend.blog.index', compact('posts','popularPost'));
		return view ('frontend.blog.index', compact('posts','postlinks'));
	}


##################################################################################################################
# ██████╗ ██████╗ ██╗███╗   ██╗████████╗
# ██╔══██╗██╔══██╗██║████╗  ██║╚══██╔══╝
# ██████╔╝██████╔╝██║██╔██╗ ██║   ██║   
# ██╔═══╝ ██╔══██╗██║██║╚██╗██║   ██║   
# ██║     ██║  ██║██║██║ ╚████║   ██║   
# ╚═╝     ╚═╝  ╚═╝╚═╝╚═╝  ╚═══╝   ╚═╝   
##################################################################################################################
	public function print($id)
	{
		if(!checkACL('author')) {
			return view('errors.frontend.403');
		}

		$post = Post::find($id);

		// Save entry to log file using built-in Monolog
		// Log::info(Auth::user()->username . " (" . Auth::user()->id . ") PRINTED article (" . $article->id . ")\r\n", 
		// 	[json_decode($article, true)]
		// );

		return view('frontend.blog.print', compact('post'));
	}


##################################################################################################################
# ███████╗███████╗ █████╗ ██████╗  ██████╗██╗  ██╗
# ██╔════╝██╔════╝██╔══██╗██╔══██╗██╔════╝██║  ██║
# ███████╗█████╗  ███████║██████╔╝██║     ███████║
# ╚════██║██╔══╝  ██╔══██║██╔══██╗██║     ██╔══██║
# ███████║███████╗██║  ██║██║  ██║╚██████╗██║  ██║
# ╚══════╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝ ╚═════╝╚═╝  ╚═╝
##################################################################################################################
	 public function search(Request $request)
	 {
		  $this->validate($request, [
				'search' => 'required'
		  ]);

		  $search = $request->get('search');

		$posts = Post::where('title', 'like', "%$search%")
			 ->orWhere('body', 'like', "%$search%")
			 ->paginate(10)
			 ->appends(['search' => $search])
		;

		// Get list of posts by year and month
		$postlinks = DB::table('posts')
			->select(DB::raw('YEAR(created_at) year, MONTH(created_at) month, MONTHNAME(created_at) month_name, COUNT(*) post_count'))
			->where('published_at', '<=', Carbon::now())
			//->where('created_at', '<=', Carbon::now()->subMonth(3))
			->groupBy('year')
			->groupBy('month')
			->orderBy('year', 'desc')
			->orderBy('month', 'desc')
			->get();

		  // Save entry to log file using built-in Monolog
		  // if (Auth::check()) {
		  //     Log::info(Auth::user()->username . " (" . Auth::user()->id . ") searched posts for " . $search);
		  // } else {
		  //     Log::info("Guest searched posts for \"" . $search . "\"");
		  // }

		  return view('frontend.blog.search', compact('posts','postlinks'));
	 }


	// public function viewImage($id)
	// {
	// 	// Save entry to log file using built-in Monolog
	// 	if(Auth::check()) {
	// 		Log::info(Auth::user()->username . " (" . Auth::user()->id . ") viewed :: Image of Post (" . $id . ")");
	// 	}else{
	// 		//Log::info(getClientIP() . " viewed :: Post id (" . $post->id . ")";
	// 		Log::info(getClientIP() . " viewed :: Image of Post (" . $id . ")");
	// 	}
	// }


##################################################################################################################
# ███████╗██╗  ██╗ ██████╗ ██╗    ██╗
# ██╔════╝██║  ██║██╔═══██╗██║    ██║
# ███████╗███████║██║   ██║██║ █╗ ██║
# ╚════██║██╔══██║██║   ██║██║███╗██║
# ███████║██║  ██║╚██████╔╝╚███╔███╔╝
# ╚══════╝╚═╝  ╚═╝ ╚═════╝  ╚══╝╚══╝ 
// Display the specified resource
##################################################################################################################
	public function getSingle($slug)
	{
		// fetch from database based on slug
		$post = Post::where('slug', '=', $slug)->first();
		//dd($post->id);

		// get previous post id
		$previous = Post::published()->where('id', '<', $post->id)->max('id');
		// get slug if record exists
		if($previous = Post::published()->find($previous)) {
			$previous = $previous->slug;
		}

		// get next post id
		$next = Post::published()->where('id', '>', $post->id)->min('id');
		// get slug if record exists
		if($next = Post::published()->find($next)) {
			$next = $next->slug;
		}

		// Add 1 to views column
		DB::table('posts')->where('slug', '=', $slug)->increment('views', 1);

		// Get list of posts by year and month
		$postlinks = DB::table('posts')
			->select(DB::raw('YEAR(created_at) year, MONTH(created_at) month, MONTHNAME(created_at) month_name, COUNT(*) post_count'))
			->where('published_at', '<=', Carbon::now())
			//->where('created_at', '<=', Carbon::now()->subMonth(3))
			->groupBy('year')
			->groupBy('month')
			->orderBy('year', 'desc')
			->orderBy('month', 'desc')
			->get();

		//$post->save();

		// Save entry to log file using built-in Monolog
		// if(Auth::check()) {
			// Log::info(Auth::user()->username . " (" . Auth::user()->id . ") viewed :: Post (" . $post->id . ")");
		// }else{
			//Log::info(getClientIP() . " viewed :: Post id (" . $post->id . ")";
			// Log::info(getClientIP() . " viewed :: Post (" . $post->id . ")");
		// }

		// return the view and pass in the post object
		return view('frontend.blog.single', compact('post','postlinks','next','previous'));
	}


##################################################################################################################
# ███████╗████████╗ ██████╗ ██████╗ ███████╗     ██████╗ ██████╗ ███╗   ███╗███╗   ███╗███████╗███╗   ██╗████████╗
# ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝    ██╔════╝██╔═══██╗████╗ ████║████╗ ████║██╔════╝████╗  ██║╚══██╔══╝
# ███████╗   ██║   ██║   ██║██████╔╝█████╗      ██║     ██║   ██║██╔████╔██║██╔████╔██║█████╗  ██╔██╗ ██║   ██║   
# ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝      ██║     ██║   ██║██║╚██╔╝██║██║╚██╔╝██║██╔══╝  ██║╚██╗██║   ██║   
# ███████║   ██║   ╚██████╔╝██║  ██║███████╗    ╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ╚═╝ ██║███████╗██║ ╚████║   ██║   
# ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝     ╚═════╝ ╚═════╝ ╚═╝     ╚═╝╚═╝     ╚═╝╚══════╝╚═╝  ╚═══╝   ╚═╝   
##################################################################################################################
	 public function storeComment(CreateCommentRequest $request, $id)
		  // public function storeComment(Request $request, $id)
	 {
		  //dd($id);
		  $post = Post::find($id);
		  //dd($project);

		  $comment = new Comment();
				// $comment->name = $request->name;
				// $comment->email = $request->email;
				$comment->user_id = Auth::user()->id;
				$comment->comment = $request->comment;
			$post->comments()->save($comment);
		  //$comment->save();

		  // Save entry to log file using built-in Monolog
		  // if (Auth::check()) {
		  //     Log::info(Auth::user()->username . " (" . Auth::user()->id . ") commented on post (" . $post->id . ")\r\n", [json_decode($comment, true)]);
		  // } else {
		  //     Log::info(Request::ip() . " commented on post " . $post->id);
		  // }

		  Session::flash('success', 'Comment added succesfully.');
		  return redirect()->route('blog.single', [$post->slug]);
	 }


}<file_sep><?php

return [
	
	// COMPANY INFORMATION
	
	'companyName' => '<NAME>', 

	'address_1' => '701 rue Principale',

	'address_2' => 'P.O. Box: 198',

	'companyCity' => 'Casselman',

	'companyState' => 'Ontario',

	'companyZip' => 'K0A 1M0',

	'companyTelephone' => '(613) 204 7525',

	'companyFax' => '',

	'companyEmail' => '<EMAIL>',

	'companyWebsite' => '',

	'HST_no' => 'HST1234',

	'WSIB_no' => 'WSIB-1-234',


	// INVOICE SETTINGS

	'termsAndConditions' => '
		<b>Terms and Conditions</b><br />
		Content of terms and conditions will go here',

	'hst_rate' => 0.13,

	'wsib_rate' => 0.06,

	'income_tax_rate' => 0.26
	
];<file_sep><?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;

use App\Category;
use App\Comment;
use App\Module;
use App\Recipe;
use App\User;
use Carbon\Carbon;
use Auth;
use DB;
use Excel;
use File;
use Image;
use JavaScript;
use Log;
use PDF;
use Purifier;
use Route;
use Session;
use Storage;
use Table;
use URL;


use App\Http\Requests\CreateRecipeRequest;
use App\Http\Requests\UpdateRecipeRequest;
use App\Http\Requests\CreateCommentRequest;

class RecipesController extends Controller
{

##################################################################################################################
#  ██████╗ ██████╗ ███╗   ██╗███████╗████████╗██████╗ ██╗   ██╗ ██████╗████████╗
# ██╔════╝██╔═══██╗████╗  ██║██╔════╝╚══██╔══╝██╔══██╗██║   ██║██╔════╝╚══██╔══╝
# ██║     ██║   ██║██╔██╗ ██║███████╗   ██║   ██████╔╝██║   ██║██║        ██║   
# ██║     ██║   ██║██║╚██╗██║╚════██║   ██║   ██╔══██╗██║   ██║██║        ██║   
# ╚██████╗╚██████╔╝██║ ╚████║███████║   ██║   ██║  ██║╚██████╔╝╚██████╗   ██║   
#  ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝  ╚═════╝   ╚═╝   
##################################################################################################################


##################################################################################################################
#  █████╗ ██████╗  ██████╗██╗  ██╗██╗██╗   ██╗███████╗
# ██╔══██╗██╔══██╗██╔════╝██║  ██║██║██║   ██║██╔════╝
# ███████║██████╔╝██║     ███████║██║██║   ██║█████╗  
# ██╔══██║██╔══██╗██║     ██╔══██║██║╚██╗ ██╔╝██╔══╝  
# ██║  ██║██║  ██║╚██████╗██║  ██║██║ ╚████╔╝ ███████╗
# ╚═╝  ╚═╝╚═╝  ╚═╝ ╚═════╝╚═╝  ╚═╝╚═╝  ╚═══╝  ╚══════╝
# Display the archived resources
##################################################################################################################
	public function archive($year, $month)
	{

      // Set the variable so we can use a button in other pages to come back to this page
      //Session::put('backURL', Route::currentRouteName());

		$archives = Recipe::with('user')->whereYear('published_at','=', $year)
			->whereMonth('published_at','=', $month)
			->where('published_at', '<=', Carbon::now())
			->get();

		// Get list of recips by year and month
		$recipelinks = DB::table('recipes')
			->select(DB::raw('YEAR(published_at) year, MONTH(published_at) month, MONTHNAME(published_at) month_name, COUNT(*) recipe_count'))
			->where('published_at', '<=', Carbon::now())
			->groupBy('year')->groupBy('month')->orderBy('year', 'desc')->orderBy('month', 'desc')->get();

		// Save the URL in a varibale so it can be used in the blog.single page to redirect the user to the archives list page
		//Session::flash('backUrl', Request::fullUrl());
      // Set the variable so we can use a button in other pages to come back to this page
      //Session::flash('archiveURL', \Request::fullUrl());
      Session::put('archiveURL', \Request::fullUrl());
      //Session::put('archiveURL', Route::currentRouteName());
		return view('recipes.archive')->withArchives($archives)->withYear($year)->withMonth($month)->withRecipelinks($recipelinks);
	}


##################################################################################################################
#  █████╗ ██████╗ ██████╗     ███████╗ █████╗ ██╗   ██╗ ██████╗ ██████╗ ██╗████████╗███████╗
# ██╔══██╗██╔══██╗██╔══██╗    ██╔════╝██╔══██╗██║   ██║██╔═══██╗██╔══██╗██║╚══██╔══╝██╔════╝
# ███████║██║  ██║██║  ██║    █████╗  ███████║██║   ██║██║   ██║██████╔╝██║   ██║   █████╗  
# ██╔══██║██║  ██║██║  ██║    ██╔══╝  ██╔══██║╚██╗ ██╔╝██║   ██║██╔══██╗██║   ██║   ██╔══╝  
# ██║  ██║██████╔╝██████╔╝    ██║     ██║  ██║ ╚████╔╝ ╚██████╔╝██║  ██║██║   ██║   ███████╗
# ╚═╝  ╚═╝╚═════╝ ╚═════╝     ╚═╝     ╚═╝  ╚═╝  ╚═══╝   ╚═════╝ ╚═╝  ╚═╝╚═╝   ╚═╝   ╚══════╝
##################################################################################################################
	public function addFavorite($id)
	{
		$user = Auth::user()->id;
		$recipe = Recipe::find($id);

		$recipe->favorites()->sync([$user], false);

		Session::flash ('success','The recipe was successfully added to your Favorites list!');
		//return redirect()->route('recipes.myFavorites','all');
		return redirect()->route('recipes.show', $id);
	}


##################################################################################################################
#  ██████╗██████╗ ███████╗ █████╗ ████████╗███████╗
# ██╔════╝██╔══██╗██╔════╝██╔══██╗╚══██╔══╝██╔════╝
# ██║     ██████╔╝█████╗  ███████║   ██║   █████╗  
# ██║     ██╔══██╗██╔══╝  ██╔══██║   ██║   ██╔══╝  
# ╚██████╗██║  ██║███████╗██║  ██║   ██║   ███████╗
#  ╚═════╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝   ╚═╝   ╚══════╝
// Show the form for creating a new resource
##################################################################################################################
   public function create()
   {
      // if(!checkACL('author')) {
      //     return view('errors.403');
      // }

      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      // find all categories in the categories table and pass them to the view
      $categories = Category::whereHas('module', function ($query) {
         $query->where('name', '=', 'recipes');
      })->orderBy('name','asc')->get();

      // Create an empty array to store the categories
      $cats = [];

      // Store the category values into the $cats array
      foreach ($categories as $category) {
         $cats[$category->id] = $category->name;
      }

      return view('recipes.create')->withCategories($cats)->withRef($ref);
   }


##################################################################################################################
# ██████╗ ███████╗██╗     ███████╗████████╗███████╗     █████╗ ██╗     ██╗     
# ██╔══██╗██╔════╝██║     ██╔════╝╚══██╔══╝██╔════╝    ██╔══██╗██║     ██║     
# ██║  ██║█████╗  ██║     █████╗     ██║   █████╗      ███████║██║     ██║     
# ██║  ██║██╔══╝  ██║     ██╔══╝     ██║   ██╔══╝      ██╔══██║██║     ██║     
# ██████╔╝███████╗███████╗███████╗   ██║   ███████╗    ██║  ██║███████╗███████╗
# ╚═════╝ ╚══════╝╚══════╝╚══════╝   ╚═╝   ╚══════╝    ╚═╝  ╚═╝╚══════╝╚══════╝
// Mass Delete selected rows - all selected records
##################################################################################################################
   public function deleteAll(Request $request)
   {
      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      //dd('TEST_DELETE');
      $this->validate($request, [
         'checked' => 'required',
      ]);
      //dd('TEST_DELETE');

      $checked = $request->input('checked');
      //dd($checked);

      // $article = Article::withTrashed()->findOrFail($checked);
      //Article::destroy($checked);
      Recipe::whereIn('id', $checked)->forceDelete();

      Session::flash('success','The recipes were deleted successfully.');
      return redirect()->route($ref);
   }


##################################################################################################################
# ██████╗ ███████╗██╗     ███████╗████████╗███████╗    ████████╗██████╗  █████╗ ███████╗██╗  ██╗███████╗██████╗ 
# ██╔══██╗██╔════╝██║     ██╔════╝╚══██╔══╝██╔════╝    ╚══██╔══╝██╔══██╗██╔══██╗██╔════╝██║  ██║██╔════╝██╔══██╗
# ██║  ██║█████╗  ██║     █████╗     ██║   █████╗         ██║   ██████╔╝███████║███████╗███████║█████╗  ██║  ██║
# ██║  ██║██╔══╝  ██║     ██╔══╝     ██║   ██╔══╝         ██║   ██╔══██╗██╔══██║╚════██║██╔══██║██╔══╝  ██║  ██║
# ██████╔╝███████╗███████╗███████╗   ██║   ███████╗       ██║   ██║  ██║██║  ██║███████║██║  ██║███████╗██████╔╝
# ╚═════╝ ╚══════╝╚══════╝╚══════╝   ╚═╝   ╚══════╝       ╚═╝   ╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝╚══════╝╚═════╝ 
// Permanently remove the specified resource from storage - individual record
##################################################################################################################
   public static function deleteTrashed($id)
   {
      // if(!checkACL('manager')) {
         // return view('errors.403');
      // }
      //dd($id);
      $recipe = Recipe::withTrashed()->findOrFail($id);
      $recipe->forceDelete();

      Session::flash ('success','The recipe was deleted successfully.');
      return redirect()->route('recipes.trashed');
   }


##################################################################################################################
# ██████╗ ███████╗███████╗████████╗██████╗  ██████╗ ██╗   ██╗
# ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔══██╗██╔═══██╗╚██╗ ██╔╝
# ██║  ██║█████╗  ███████╗   ██║   ██████╔╝██║   ██║ ╚████╔╝ 
# ██║  ██║██╔══╝  ╚════██║   ██║   ██╔══██╗██║   ██║  ╚██╔╝  
# ██████╔╝███████╗███████║   ██║   ██║  ██║╚██████╔╝   ██║   
# ╚═════╝ ╚══════╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝    ╚═╝   
// Remove the specified resource from storage
// Used in the index page and trashAll action to soft delete multiple records
##################################################################################################################
   public function destroy($id)
   {
      // if(!checkACL('author')) {
      //     return view('errors.403');
      // }

      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      $recipe = Recipe::findOrFail($id);
         $recipe->published_at = Null;
            // Delete related favorites
            $favorites = DB::select('select * from recipe_user where recipe_id = '. $id, [1]);
              foreach($favorites as $favorite) {
               $recipe->favoriteRecipes()->detach($favorite);
              }
         $recipe->save();
      $recipe->delete();

      // Save entry to log file using built-in Monolog
      //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") DELETED article (" . $article->id . ")\r\n",
      //    [json_decode($article, true)]
      //);

      Session::flash('success','The recipe was trashed successfully.');
      return redirect()->route($ref);
   }


##################################################################################################################
# ██████╗  ██████╗ ██╗    ██╗███╗   ██╗██╗      ██████╗  █████╗ ██████╗     ███████╗██╗  ██╗ ██████╗███████╗██╗     
# ██╔══██╗██╔═══██╗██║    ██║████╗  ██║██║     ██╔═══██╗██╔══██╗██╔══██╗    ██╔════╝╚██╗██╔╝██╔════╝██╔════╝██║     
# ██║  ██║██║   ██║██║ █╗ ██║██╔██╗ ██║██║     ██║   ██║███████║██║  ██║    █████╗   ╚███╔╝ ██║     █████╗  ██║     
# ██║  ██║██║   ██║██║███╗██║██║╚██╗██║██║     ██║   ██║██╔══██║██║  ██║    ██╔══╝   ██╔██╗ ██║     ██╔══╝  ██║     
# ██████╔╝╚██████╔╝╚███╔███╔╝██║ ╚████║███████╗╚██████╔╝██║  ██║██████╔╝    ███████╗██╔╝ ██╗╚██████╗███████╗███████╗
# ╚═════╝  ╚═════╝  ╚══╝╚══╝ ╚═╝  ╚═══╝╚══════╝ ╚═════╝ ╚═╝  ╚═╝╚═════╝     ╚══════╝╚═╝  ╚═╝ ╚═════╝╚══════╝╚══════╝
##################################################################################################################
   public function downloadExcel($type)
   {
      // if(!checkACL('manager')) {
      //   // Save entry to log file of failure
      //   Log::warning(Auth::user()->username . " (" . Auth::user()->id . ") tried to access :: Articles / Download");
      //   return view('errors.403');
      // }

      // $referrer = request()->headers->get('referer');
      // //dd($referrer);
      // if ($referrer == 'http://localhost:8000/recipes/myRecipes') {
      //    $data = Recipe::myRecipes()->get()->toArray();
      // // } elseif ($referrer == 'http://localhost:8000/backend/articles'){
      // //     $data = Article::get()->toArray();
      // } else {
      //    $data = Recipe::get()->toArray();
      // }
      if(!checkACL('manager')) {
         return view('errors.403');
      }

      if(app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName() == 'recipes.index') {
            $data = Recipe::published()->get()->toArray();
      }
      if(app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName() == 'recipes.newRecipes') {
            $data = Recipe::newRecipes()->get()->toArray();
      }
      if(app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName() == 'recipes.myRecipes') {
            $data = Recipe::myRecipes()->get()->toArray();
      }
      if(app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName() == 'recipes.unpublished') {
            $data = Recipe::unpublished()->get()->toArray();
      }
      if(app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName() == 'recipes.future') {
            $data = Recipe::future()->get()->toArray();
      }
      if(app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName() == 'recipes.trashed') {
            $data = Recipe::trashedCount()->get()->toArray();
      }

      // Save entry to log file of failure
      //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") downloaded :: articles");

      return Excel::create('Recipes_List', function($excel) use ($data) {
         $excel->sheet('mySheet', function($sheet) use ($data)
         {
            $sheet->fromArray($data);
         });
      })->download($type);
   }


##################################################################################################################
# ██████╗ ██╗   ██╗██████╗ ██╗     ██╗ ██████╗ █████╗ ████████╗███████╗
# ██╔══██╗██║   ██║██╔══██╗██║     ██║██╔════╝██╔══██╗╚══██╔══╝██╔════╝
# ██║  ██║██║   ██║██████╔╝██║     ██║██║     ███████║   ██║   █████╗  
# ██║  ██║██║   ██║██╔═══╝ ██║     ██║██║     ██╔══██║   ██║   ██╔══╝  
# ██████╔╝╚██████╔╝██║     ███████╗██║╚██████╗██║  ██║   ██║   ███████╗
# ╚═════╝  ╚═════╝ ╚═╝     ╚══════╝╚═╝ ╚═════╝╚═╝  ╚═╝   ╚═╝   ╚══════╝
// DUPLICATE :: Duplicate the specified resource in storage.
##################################################################################################################
   public function duplicate($id)
   {
      //if(!checkACL('manager')) {
      //  // Save entry to log file of failure
      //  Log::warning(Auth::user()->username . " (" . Auth::user()->id . ") tried to access :: Articles / Duplicate");
      //  return view('errors.403');
      //}

      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      $recipe = Recipe::find($id);
        $newRecipe = $recipe->replicate();
        $newRecipe->user_id = Auth::user()->id;
      $newRecipe->save();

      // change the user_id field to be that of the user that is currently logged in
      
      //$newArticle->views = 0;
      //$newArticle->save();

      // Save entry to log file using built-in Monolog
      //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") duplicated :: article " . $article->id . " to article ". $newArticle->id);

      Session::flash ('success','The recipe was duplicated successfully!');
      return redirect()->route($ref);
   }


##################################################################################################################
# ███████╗██████╗ ██╗████████╗
# ██╔════╝██╔══██╗██║╚══██╔══╝
# █████╗  ██║  ██║██║   ██║   
# ██╔══╝  ██║  ██║██║   ██║   
# ███████╗██████╔╝██║   ██║   
# ╚══════╝╚═════╝ ╚═╝   ╚═╝   
// Show the form for editing the specified resource
##################################################################################################################
   public function edit($id)
   {
      // if(!checkACL('author')) {
      //     return view('errors.403');
      // }

      // Pass along the ROUTE value of the previous page
      //$ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();
      //Session::put('fullURL', \Request::fullUrl());

      // Find the article to edit
      $recipe = Recipe::findOrFail($id);

      // find all categories in the categories table and pass them to the view
      $categories = Category::whereHas('module', function ($query) {
         $query->where('name', '=', 'recipes');
      })->get();

      // Create an empty array to store the categories
      $cats = [];
      // Store the category values into the $cats array
      foreach ($categories as $category) {
         $cats[$category->id] = $category->name;
      }

      return view('recipes.edit', compact('recipe'))->withCategories($cats);
      //->withRef($ref);
   }


##################################################################################################################
# ███████╗██╗   ██╗████████╗██╗   ██╗██████╗ ███████╗
# ██╔════╝██║   ██║╚══██╔══╝██║   ██║██╔══██╗██╔════╝
# █████╗  ██║   ██║   ██║   ██║   ██║██████╔╝█████╗  
# ██╔══╝  ██║   ██║   ██║   ██║   ██║██╔══██╗██╔══╝  
# ██║     ╚██████╔╝   ██║   ╚██████╔╝██║  ██║███████╗
# ╚═╝      ╚═════╝    ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
// Display a list of resources that will be published at a later date
##################################################################################################################
   public function future(Request $request, $key=null)
   {
      // if(!checkACL('guest')) {
      //     return view('errors.403');
      // }

      //$alphas = range('A', 'Z');
      $alphas = DB::table('recipes')
         ->select(DB::raw('DISTINCT LEFT(title, 1) as letter'))
         // ->where('personal', '!=', 1)
         ->where('published_at','>', Carbon::Now())
         ->orderBy('letter')
         ->get();
         //dd($alphas);

      $letters = [];
      foreach($alphas as $alpha) {
         $letters[] = $alpha->letter;
      }

      // If $key value is passed
      if ($key) {
         $recipes = Recipe::with('user','category')->future()
            ->where('title', 'like', $key . '%')
            ->orderBy('title', 'asc')
            ->get();
         return view('recipes.future', compact('recipes','letters'));
      }

      // No $key value is passed
      $recipes = Recipe::with('user','category')->future()->get();
      return view('recipes.future', compact('recipes','letters'));
   }


##################################################################################################################
# ██╗███╗   ███╗██████╗  ██████╗ ██████╗ ████████╗
# ██║████╗ ████║██╔══██╗██╔═══██╗██╔══██╗╚══██╔══╝
# ██║██╔████╔██║██████╔╝██║   ██║██████╔╝   ██║   
# ██║██║╚██╔╝██║██╔═══╝ ██║   ██║██╔══██╗   ██║   
# ██║██║ ╚═╝ ██║██║     ╚██████╔╝██║  ██║   ██║   
# ╚═╝╚═╝     ╚═╝╚═╝      ╚═════╝ ╚═╝  ╚═╝   ╚═╝   
// IMPORT :: Show the form for importing entries to storage.
##################################################################################################################
   public function import()
   {
      // if(!checkACL('manager')) {
      //   // Save entry to log file of failure
      //   Log::warning(Auth::user()->username . " (" . Auth::user()->id . ") tried to access :: Articles / Import");
      //   return view('errors.403');
      // }

      // Save entry to log file of failure
      //Log::warning(Auth::user()->username . " (" . Auth::user()->id . ") accessed :: Articles / Import");

      return view('recipes.import');
   }


##################################################################################################################
# ██╗███╗   ███╗██████╗  ██████╗ ██████╗ ████████╗    ███████╗██╗   ██╗███╗   ██╗ ██████╗████████╗██╗ ██████╗ ███╗   ██╗
# ██║████╗ ████║██╔══██╗██╔═══██╗██╔══██╗╚══██╔══╝    ██╔════╝██║   ██║████╗  ██║██╔════╝╚══██╔══╝██║██╔═══██╗████╗  ██║
# ██║██╔████╔██║██████╔╝██║   ██║██████╔╝   ██║       █████╗  ██║   ██║██╔██╗ ██║██║        ██║   ██║██║   ██║██╔██╗ ██║
# ██║██║╚██╔╝██║██╔═══╝ ██║   ██║██╔══██╗   ██║       ██╔══╝  ██║   ██║██║╚██╗██║██║        ██║   ██║██║   ██║██║╚██╗██║
# ██║██║ ╚═╝ ██║██║     ╚██████╔╝██║  ██║   ██║       ██║     ╚██████╔╝██║ ╚████║╚██████╗   ██║   ██║╚██████╔╝██║ ╚████║
# ╚═╝╚═╝     ╚═╝╚═╝      ╚═════╝ ╚═╝  ╚═╝   ╚═╝       ╚═╝      ╚═════╝ ╚═╝  ╚═══╝ ╚═════╝   ╚═╝   ╚═╝ ╚═════╝ ╚═╝  ╚═══╝
##################################################################################################################
   public function importExcel()
   {
      // if(!checkACL('manager')) {
      //   // Save entry to log file of failure
      //   Log::warning(Auth::user()->username . " (" . Auth::user()->id . ") tried to access :: Admin / Articles / Import");
      //   return view('errors.403');
      // }

      if(Input::hasFile('import_file')) {
            $path = Input::file('import_file')->getRealPath();
            $data = Excel::load($path, function($reader) {
         })->get();

         if(!empty($data) && $data->count()) {
            foreach ($data as $key => $value) {
               $insert[] = [
                  'user_id'            => $value->user_id,
                  'category_id'        => $value->category_id,
                  'title'              => $value->title,            
                  'description_eng'    => $value->description_eng,
                  'description_fre'    => $value->description_fre,
                  'views'              =>  0,
                  'deleted_at'         => $value->deleted_at,
                  'published_at'       => $value->published_at,
                  'created_at'         => $value->created_at,
                  'updated_at'         => $value->updated_at,
               ];
            }

            if(!empty($insert)) {
               DB::table('articles')->insert($insert);

               // Save entry to log file of failure
               //Log::warning(Auth::user()->username . " (" . Auth::user()->id . ") imported :: articles");

               Session::flash('success', $data->count() . ' articles imported successfully!');
               return redirect()->route('articles.index');
            }
         }
      }
      return back();
   }


##################################################################################################################
# ██╗███╗   ██╗██████╗ ███████╗██╗  ██╗
# ██║████╗  ██║██╔══██╗██╔════╝╚██╗██╔╝
# ██║██╔██╗ ██║██║  ██║█████╗   ╚███╔╝ 
# ██║██║╚██╗██║██║  ██║██╔══╝   ██╔██╗ 
# ██║██║ ╚████║██████╔╝███████╗██╔╝ ██╗
# ╚═╝╚═╝  ╚═══╝╚═════╝ ╚══════╝╚═╝  ╚═╝
// Display a list of resources
##################################################################################################################
	public function index(Request $request, $key=null)
	{
		// if(!checkACL('guest')) {
  		//         //return view('errors.403');
		// 	abort(403, 'Unauthorized action');
  		//     }

		// Save entry to log file using built-in Monolog
		// if (Auth::check()) {
		// 	Log::info(Auth::user()->username . " (" . Auth::user()->id . ") accessed :: Recipes / Index");
		// } else {
		// 	Log::info( getClientIP() . " accessed :: Recipes / index");
		// }

      // Set the variable so we can use a button in other pages to come back to this page
      Session::put('backURL', Route::currentRouteName());

		// Get list of recips by year and month
		$recipelinks = DB::table('recipes')
			->select(DB::raw('YEAR(published_at) year, MONTH(published_at) month, MONTHNAME(published_at) month_name, COUNT(*) recipe_count'))
			->where('published_at', '<=', Carbon::now())
			->groupBy('year')->groupBy('month')->orderBy('year', 'desc')->orderBy('month', 'desc')->get();

		//$alphas = range('A', 'Z');
		$alphas = DB::table('recipes')
			->select(DB::raw('DISTINCT LEFT(title, 1) as letter'))
			->where('published_at', '<', Carbon::now())
			->orderBy('letter')
			->get();
			//dd($alphas);

		$letters = [];
		foreach($alphas as $alpha) {
			$letters[] = $alpha->letter;
		}
		//dd($letters);

		// if ($key == 'all') {
		// 	// Display all the user's recipes plus the one from other users that are not marked as personal/private
		// 	$recipes = Recipe::with('user','category')->published()
		// 	// ->where('personal','!=',1)
		// 	// ->where('published','>=', $pub)
		// 	->orderBy('title', 'asc')
		// 	->get();
		
		// 	return view('recipes.index', compact('recipes','letters'));
		// }

		// if ($key != 'all') {
		// 	$recipes = Recipe::with('user','category')->published()
		// 		// ->where('personal', '!=', 1)
		// 		// ->where('published','>=', $pub)
		// 		->where('title', 'like', $key . '%')
		// 		->orderBy('title', 'asc')
		// 		->get();
		
		// 	return view('recipes.index', compact('recipes','letters'));
		// }

		// If $key value is passed
		if ($key) {
			$recipes = Recipe::with('user','category')
				->published()
				->where('title', 'like', $key . '%')
				->orderBy('title', 'asc')
				->get();
			return view('recipes.index', compact('recipes','letters','recipelinks'));
		}

		// No $key value is passed
		$recipes = Recipe::with('user','category')
			->published()
			->orderBy('title', 'asc')
			->get();
		return view('recipes.index', compact('recipes','letters','recipelinks'));

		// } else {
		//   if ($key == 'all') {
		//     // Display all the user's recipes that are not marked as personal/private
		//     $recipes = Recipe::where('personal','!=',1)->orderBy('title', 'asc')->get();
		//     return view('recipes.index')->withRecipes($recipes);
		//   }

		//   if ($key != 'all') {
		//     $recipes = Recipe::where('personal', '!=', 1)->where('title', 'like', $key . '%')->get();
		//     return view('recipes.index')->withRecipes($recipes);
		//   }
		// }
	}


##################################################################################################################
# ███╗   ███╗ █████╗ ██╗  ██╗███████╗    ██████╗ ██████╗ ██╗██╗   ██╗ █████╗ ████████╗███████╗
# ████╗ ████║██╔══██╗██║ ██╔╝██╔════╝    ██╔══██╗██╔══██╗██║██║   ██║██╔══██╗╚══██╔══╝██╔════╝
# ██╔████╔██║███████║█████╔╝ █████╗      ██████╔╝██████╔╝██║██║   ██║███████║   ██║   █████╗  
# ██║╚██╔╝██║██╔══██║██╔═██╗ ██╔══╝      ██╔═══╝ ██╔══██╗██║╚██╗ ██╔╝██╔══██║   ██║   ██╔══╝  
# ██║ ╚═╝ ██║██║  ██║██║  ██╗███████╗    ██║     ██║  ██║██║ ╚████╔╝ ██║  ██║   ██║   ███████╗
# ╚═╝     ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝    ╚═╝     ╚═╝  ╚═╝╚═╝  ╚═══╝  ╚═╝  ╚═╝   ╚═╝   ╚══════╝
##################################################################################################################
   public function makePrivate($id)
   {
      // Pass along the ROUTE value of the previous page
      //$ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();
      // Set the variable so we can use a button in other pages to come back to this page
      //Session::put('backURL', Route::currentRouteName());
      //Session::put('fullURL', \Request::fullUrl());

      $recipe = Recipe::find($id);
         $recipe->personal = 1;
      $recipe->save();

      // Save entry to log file using built-in Monolog
      //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") MADE recipe (" . $recipe->id . ") PRIVATE \r\n", [json_decode($recipe, true)]);

      Session::flash('success','The recipe was successfully made private');
      //return redirect()->route($ref);
      return redirect()->route('recipes.show', $id);
   }


##################################################################################################################
# ███╗   ███╗██╗   ██╗    ███████╗ █████╗ ██╗   ██╗ ██████╗ ██████╗ ██╗████████╗███████╗███████╗
# ████╗ ████║╚██╗ ██╔╝    ██╔════╝██╔══██╗██║   ██║██╔═══██╗██╔══██╗██║╚══██╔══╝██╔════╝██╔════╝
# ██╔████╔██║ ╚████╔╝     █████╗  ███████║██║   ██║██║   ██║██████╔╝██║   ██║   █████╗  ███████╗
# ██║╚██╔╝██║  ╚██╔╝      ██╔══╝  ██╔══██║╚██╗ ██╔╝██║   ██║██╔══██╗██║   ██║   ██╔══╝  ╚════██║
# ██║ ╚═╝ ██║   ██║       ██║     ██║  ██║ ╚████╔╝ ╚██████╔╝██║  ██║██║   ██║   ███████╗███████║
# ╚═╝     ╚═╝   ╚═╝       ╚═╝     ╚═╝  ╚═╝  ╚═══╝   ╚═════╝ ╚═╝  ╚═╝╚═╝   ╚═╝   ╚══════╝╚══════╝
// MY FAVORITES :: Display a listing of the resource that have been favorited by a specific user.
##################################################################################################################
	public function myFavorites()
	{
      // Set the variable so we can use a button in other pages to come back to this page
      Session::put('backURL', Route::currentRouteName());
      
		// find the favorites
		$favs = DB::table('recipe_user')
			->where('user_id','=',Auth::user()->id)
			->get();
		//dd($favs);

		// Create an empty array to store the recipes        
		$recipes = [];

		// Store the recipe values into the $recipes array
		foreach ($favs as $fav)
		{
			$recipes[$fav->id] = Recipe::find($fav->recipe_id);
		}
		//dd($recipeIds);

		// $alphas = DB::table('recipes')
		// 	->select(DB::raw('DISTINCT LEFT(title, 1) as letter'))
		// 	->whereIn('id', $recipeIds->recipe->id)
		// 	->orderBy('letter')
		// 	->get();
		// dd($alphas);

		$letters = [];
		// foreach($alphas as $alpha) {
		// 	$letters[] = $alpha->letter;
		// }
		//dd($letters);

		// Sort the recipes array by title
		// $recipes = array_values(array_sort($recipes, function ($value) {
		// 	return $value['title'];
		// }));

		return view('recipes.myFavorites', compact('recipes','letters'));
	}


##################################################################################################################
# ███╗   ███╗██╗   ██╗    ██████╗ ███████╗ ██████╗██╗██████╗ ███████╗███████╗
# ████╗ ████║╚██╗ ██╔╝    ██╔══██╗██╔════╝██╔════╝██║██╔══██╗██╔════╝██╔════╝
# ██╔████╔██║ ╚████╔╝     ██████╔╝█████╗  ██║     ██║██████╔╝█████╗  ███████╗
# ██║╚██╔╝██║  ╚██╔╝      ██╔══██╗██╔══╝  ██║     ██║██╔═══╝ ██╔══╝  ╚════██║
# ██║ ╚═╝ ██║   ██║       ██║  ██║███████╗╚██████╗██║██║     ███████╗███████║
# ╚═╝     ╚═╝   ╚═╝       ╚═╝  ╚═╝╚══════╝ ╚═════╝╚═╝╚═╝     ╚══════╝╚══════╝
// Display a listing of the resource that belong to a specific user.
##################################################################################################################
	public function myRecipes($key=null)
	{
      // Set the variable so we can use a button in other pages to come back to this page
      Session::put('backURL', Route::currentRouteName());

		if (Auth::check()) {
			$alphas = DB::table('recipes')
				->select(DB::raw('DISTINCT LEFT(title, 1) as letter'))
				->where('user_id','=', Auth::user()->id)
				// ->where('published_at', '<', Carbon::now())
				->orderBy('letter')
				->get();
			//dd($alphas);

			$letters = [];
			foreach($alphas as $alpha) {
				$letters[] = $alpha->letter;
			}

			// if ($key == 'all') {
			// 	// Display all the user's recipes plus the one from other users that are not marked as personal/private
			// 	$recipes = Recipe::with('user','category')
			// 		->where('user_id','=', Auth::user()->id)
			// 		->orderBy('title', 'asc')
			// 		->get();
			
			// 	return view('recipes.myRecipes', compact('recipes','letters'));
			// }
			
			// if ($key != 'all') {
			// 	$recipes = Recipe::with('user','category')
			// 		->where('user_id','=', Auth::user()->id)
			// 		->where('title', 'like', $key . '%')
			// 		->orderBy('title', 'asc')
			// 		->get();
			
			// 	return view('recipes.myRecipes', compact('recipes','letters'));
			// }
					// If $key value is passed
			if ($key) {
				$recipes = Recipe::with('user','category')->myRecipes()
					->where('title', 'like', $key . '%')
					->orderBy('title', 'asc')
					->get();
				return view('recipes.myRecipes', compact('recipes','letters'));
			}

			// No $key value is passed
			$recipes = Recipe::with('user','category')->myRecipes()->get();
			return view('recipes.myRecipes', compact('recipes','letters'));
		}
	}


##################################################################################################################
# ███╗   ██╗███████╗██╗    ██╗    ██████╗ ███████╗ ██████╗██╗██████╗ ███████╗███████╗
# ████╗  ██║██╔════╝██║    ██║    ██╔══██╗██╔════╝██╔════╝██║██╔══██╗██╔════╝██╔════╝
# ██╔██╗ ██║█████╗  ██║ █╗ ██║    ██████╔╝█████╗  ██║     ██║██████╔╝█████╗  ███████╗
# ██║╚██╗██║██╔══╝  ██║███╗██║    ██╔══██╗██╔══╝  ██║     ██║██╔═══╝ ██╔══╝  ╚════██║
# ██║ ╚████║███████╗╚███╔███╔╝    ██║  ██║███████╗╚██████╗██║██║     ███████╗███████║
# ╚═╝  ╚═══╝╚══════╝ ╚══╝╚══╝     ╚═╝  ╚═╝╚══════╝ ╚═════╝╚═╝╚═╝     ╚══════╝╚══════╝
// Display a listing of the resource that were created since the user's last login.
##################################################################################################################
   public function newRecipes(Request $request, $key=null)
   {
      if(!checkACL('author')) {
          return view('errors.403');
      }

      // Set the variable so we can use a button in other pages to come back to this page
      Session::put('backURL', Route::currentRouteName());

      //$alphas = range('A', 'Z');
      $alphas = DB::table('recipes')
         ->select(DB::raw('DISTINCT LEFT(title, 1) as letter'))
         ->where('created_at', '>=' , Auth::user()->last_login_date)
         //->where('user_id', '=', Auth::user()->id)
         // ->where('personal', '!=', 1)
         // ->where('published_at','!=', null)
         ->orderBy('letter')
         ->get();
      //dd($alphas);

      $letters = [];
      foreach($alphas as $alpha) {
        $letters[] = $alpha->letter;
      }

      // If $key value is passed
      if ($key) {
         $recipes = Recipe::with('user','category')->newRecipes()
            ->where('title', 'like', $key . '%')
            ->get();
         return view('recipes.newRecipes', compact('recipes','letters'));
      }

      $recipes = Recipe::with('user','category')->newRecipes()->get();
      return view('recipes.newRecipes', compact('recipes','letters'));
   }


##################################################################################################################
# ██████╗ ██████╗ ███████╗    ██╗   ██╗██╗███████╗██╗    ██╗
# ██╔══██╗██╔══██╗██╔════╝    ██║   ██║██║██╔════╝██║    ██║
# ██████╔╝██║  ██║█████╗      ██║   ██║██║█████╗  ██║ █╗ ██║
# ██╔═══╝ ██║  ██║██╔══╝      ╚██╗ ██╔╝██║██╔══╝  ██║███╗██║
# ██║     ██████╔╝██║          ╚████╔╝ ██║███████╗╚███╔███╔╝
# ╚═╝     ╚═════╝ ╚═╝           ╚═══╝  ╚═╝╚══════╝ ╚══╝╚══╝ 
// 
##################################################################################################################
   // public function exportPDF()
   // {
   //   // if(!checkACL('manager')) {
   //   //   return view('errors.403');
   //   // }

   //   $data = Article::get()->toArray();
   //   return Excel::create('Articles_List', function($excel) use ($data) {
   //     $excel->sheet('mySheet', function($sheet) use ($data)
   //     {
   //       $sheet->fromArray($data);
   //     });
   //   })->download("pdf");
   // }

   // public function downloadPDF()
   // {
   //   $pdf = PDF::loadView('articles.pdfView');
   //   return $pdf->download('articles.pdf');
   // }

   public function pdfview(Request $request)
   {
      //$articles = DB::table("articles")->get();

      $referrer = request()->headers->get('referer');
      if ($referrer == 'http://localhost:8000/backend/recipes/myRecipes') {
         $data = Recipe::myRecipes()->get();
      } else {
         $data = Recipe::All();
      }

      view()->share('recipes',$data);

      if($request->has('download')){
         $pdf = PDF::loadView('recipes.pdfDownload');
         //$pdf->setPaper('A4', 'landscape');
         return $pdf->download('recipes.pdf');
      }

      return view('recipes.pdfPreview');
   }


##################################################################################################################
# ██████╗ ██████╗ ██╗███╗   ██╗████████╗
# ██╔══██╗██╔══██╗██║████╗  ██║╚══██╔══╝
# ██████╔╝██████╔╝██║██╔██╗ ██║   ██║   
# ██╔═══╝ ██╔══██╗██║██║╚██╗██║   ██║   
# ██║     ██║  ██║██║██║ ╚████║   ██║   
# ╚═╝     ╚═╝  ╚═╝╚═╝╚═╝  ╚═══╝   ╚═╝   
##################################################################################################################
	public function print($id)
	{
		$recipe = Recipe::find($id);

		// Save entry to log file using built-in Monolog
		// Log::info(Auth::user()->username . " (" . Auth::user()->id . ") PRINTED recipe (" . $recipe->id . ")\r\n", [json_decode($recipe, true)]);

		return view('recipes.print')->withRecipe($recipe);
	}


##################################################################################################################
# ██████╗ ██╗   ██╗██████╗ ██╗     ██╗███████╗██╗  ██╗
# ██╔══██╗██║   ██║██╔══██╗██║     ██║██╔════╝██║  ██║
# ██████╔╝██║   ██║██████╔╝██║     ██║███████╗███████║
# ██╔═══╝ ██║   ██║██╔══██╗██║     ██║╚════██║██╔══██║
# ██║     ╚██████╔╝██████╔╝███████╗██║███████║██║  ██║
# ╚═╝      ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚══════╝╚═╝  ╚═╝
##################################################################################################################
   public function publish($id)
   {
      // Pass along the ROUTE value of the previous page
      //$ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();
      Session::put('fullURL', \Request::fullUrl());


      $recipe = Recipe::find($id);
        $recipe->published_at = Carbon::now();
        $recipe->deleted_at = Null;
      $recipe->save();

      Session::flash ('success','The recipe was successfully published.');
      //return redirect()->route($ref);
      return redirect()->route('recipes.show', $id);
   }


##################################################################################################################
# ██████╗ ██╗   ██╗██████╗ ██╗     ██╗███████╗██╗  ██╗     █████╗ ██╗     ██╗     
# ██╔══██╗██║   ██║██╔══██╗██║     ██║██╔════╝██║  ██║    ██╔══██╗██║     ██║     
# ██████╔╝██║   ██║██████╔╝██║     ██║███████╗███████║    ███████║██║     ██║     
# ██╔═══╝ ██║   ██║██╔══██╗██║     ██║╚════██║██╔══██║    ██╔══██║██║     ██║     
# ██║     ╚██████╔╝██████╔╝███████╗██║███████║██║  ██║    ██║  ██║███████╗███████╗
# ╚═╝      ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚══════╝╚═╝  ╚═╝    ╚═╝  ╚═╝╚══════╝╚══════╝
##################################################################################################################
   public function publishAll(Request $request)
   {
      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      //dd('TEST_DELETE');
      $this->validate($request, [
         'checked' => 'required',
      ]);
      //dd('TEST_DELETE');

      $checked = $request->input('checked');
      //dd($checked);

      // $article = Article::withTrashed()->findOrFail($checked);
      //Article::destroy($checked);
      //Article::whereIn('id', $checked)->publish();
      foreach ($checked as $item) {
         //dd($item);
         $recipe = Recipe::withTrashed()->find($item);
         //dd($article);
            $recipe->published_at = Carbon::now();
            $recipe->deleted_at = Null;
         $recipe->save();
      }

      Session::flash('success','The recipes were published successfully.');
      return redirect()->route($ref);
   }


##################################################################################################################
# ██████╗ ██╗   ██╗██████╗ ██╗     ██╗███████╗██╗  ██╗███████╗██████╗ 
# ██╔══██╗██║   ██║██╔══██╗██║     ██║██╔════╝██║  ██║██╔════╝██╔══██╗
# ██████╔╝██║   ██║██████╔╝██║     ██║███████╗███████║█████╗  ██║  ██║
# ██╔═══╝ ██║   ██║██╔══██╗██║     ██║╚════██║██╔══██║██╔══╝  ██║  ██║
# ██║     ╚██████╔╝██████╔╝███████╗██║███████║██║  ██║███████╗██████╔╝
# ╚═╝      ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚══════╝╚═╝  ╚═╝╚══════╝╚═════╝ 
##################################################################################################################
   public function published(Request $request, $key=null)
   {
      if(!checkACL('user')) {
          return view('errors.403');
      }

      //$alphas = range('A', 'Z');
        $alphas = DB::table('recipes')
         ->select(DB::raw('DISTINCT LEFT(title, 1) as letter'))
         ->where('published_at','<', Carbon::Now())
         ->where('deleted_at','=', Null)
         ->orderBy('letter')
         ->get();

      $letters = [];
      foreach($alphas as $alpha) {
        $letters[] = $alpha->letter;
      }

      // If $key value is passed
      if ($key) {
         $recipes = Recipe::with('user','category')->published()
            ->where('title', 'like', $key . '%')
            ->orderBy('title', 'asc')
            ->get();
         return view('recipes.published', compact('recipes','letters'));
      }

      // No $key value is passed
      $recipes = Recipe::with('user','category')->published()->get();
      return view('recipes.published', compact('recipes','letters'));
   }


##################################################################################################################
# ██████╗ ███████╗███╗   ███╗ ██████╗ ██╗   ██╗███████╗    ███████╗ █████╗ ██╗   ██╗ ██████╗ ██████╗ ██╗████████╗███████╗
# ██╔══██╗██╔════╝████╗ ████║██╔═══██╗██║   ██║██╔════╝    ██╔════╝██╔══██╗██║   ██║██╔═══██╗██╔══██╗██║╚══██╔══╝██╔════╝
# ██████╔╝█████╗  ██╔████╔██║██║   ██║██║   ██║█████╗      █████╗  ███████║██║   ██║██║   ██║██████╔╝██║   ██║   █████╗  
# ██╔══██╗██╔══╝  ██║╚██╔╝██║██║   ██║╚██╗ ██╔╝██╔══╝      ██╔══╝  ██╔══██║╚██╗ ██╔╝██║   ██║██╔══██╗██║   ██║   ██╔══╝  
# ██║  ██║███████╗██║ ╚═╝ ██║╚██████╔╝ ╚████╔╝ ███████╗    ██║     ██║  ██║ ╚████╔╝ ╚██████╔╝██║  ██║██║   ██║   ███████╗
# ╚═╝  ╚═╝╚══════╝╚═╝     ╚═╝ ╚═════╝   ╚═══╝  ╚══════╝    ╚═╝     ╚═╝  ╚═╝  ╚═══╝   ╚═════╝ ╚═╝  ╚═╝╚═╝   ╚═╝   ╚══════╝
##################################################################################################################
	public function removeFavorite($id)
	{
		$user = Auth::user()->id;
		$recipe = Recipe::find($id);

		$recipe->favorites()->detach($user);

		Session::flash ('success','The recipe was successfully removed to your Favorites list!');
		// return redirect()->route('recipes.index','all');
		//return redirect()->route('recipes.myFavorites','all');
		return redirect()->route('recipes.show', $id);
	}


##################################################################################################################
# ██████╗ ███████╗███╗   ███╗ ██████╗ ██╗   ██╗███████╗    ██████╗ ██████╗ ██╗██╗   ██╗ █████╗ ████████╗███████╗
# ██╔══██╗██╔════╝████╗ ████║██╔═══██╗██║   ██║██╔════╝    ██╔══██╗██╔══██╗██║██║   ██║██╔══██╗╚══██╔══╝██╔════╝
# ██████╔╝█████╗  ██╔████╔██║██║   ██║██║   ██║█████╗      ██████╔╝██████╔╝██║██║   ██║███████║   ██║   █████╗  
# ██╔══██╗██╔══╝  ██║╚██╔╝██║██║   ██║╚██╗ ██╔╝██╔══╝      ██╔═══╝ ██╔══██╗██║╚██╗ ██╔╝██╔══██║   ██║   ██╔══╝  
# ██║  ██║███████╗██║ ╚═╝ ██║╚██████╔╝ ╚████╔╝ ███████╗    ██║     ██║  ██║██║ ╚████╔╝ ██║  ██║   ██║   ███████╗
# ╚═╝  ╚═╝╚══════╝╚═╝     ╚═╝ ╚═════╝   ╚═══╝  ╚══════╝    ╚═╝     ╚═╝  ╚═╝╚═╝  ╚═══╝  ╚═╝  ╚═╝   ╚═╝   ╚══════╝
##################################################################################################################
   public function removePrivate($id)
   {
      // Pass along the ROUTE value of the previous page
      //$ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();
      Session::put('fullURL', \Request::fullUrl());

      $recipe = Recipe::find($id);
         $recipe->personal = 0;
      $recipe->save();

      // Save entry to log file using built-in Monolog
      //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") REMOVE PRIVATE from recipe (" . $recipe->id . ")\r\n", 
      //    [json_decode($recipe, true)]
      //);

      Session::flash('success','The recipe was successfully removed from private');
      //return redirect()->route($ref);
      return redirect()->route('recipes.show', $id);
   }


##################################################################################################################
# ██████╗ ███████╗███████╗███████╗████████╗    ██╗   ██╗██╗███████╗██╗    ██╗███████╗
# ██╔══██╗██╔════╝██╔════╝██╔════╝╚══██╔══╝    ██║   ██║██║██╔════╝██║    ██║██╔════╝
# ██████╔╝█████╗  ███████╗█████╗     ██║       ██║   ██║██║█████╗  ██║ █╗ ██║███████╗
# ██╔══██╗██╔══╝  ╚════██║██╔══╝     ██║       ╚██╗ ██╔╝██║██╔══╝  ██║███╗██║╚════██║
# ██║  ██║███████╗███████║███████╗   ██║        ╚████╔╝ ██║███████╗╚███╔███╔╝███████║
# ╚═╝  ╚═╝╚══════╝╚══════╝╚══════╝   ╚═╝         ╚═══╝  ╚═╝╚══════╝ ╚══╝╚══╝ ╚══════╝
// RESET VIEWS COUNT
##################################################################################################################
   public function resetViews($id)
   {
      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      $recipe = Recipe::find($id);
         $recipe->views = 0;
      $recipe->save();

      // Save entry to log file using built-in Monolog
      //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") MADE recipe (" . $recipe->id . ") PRIVATE \r\n", [json_decode($recipe, true)]);

      Session::flash('success','The recipe\'s views count was reset to 0.');
      return redirect()->route($ref);
   }


##################################################################################################################
# ██████╗ ███████╗███████╗████████╗ ██████╗ ██████╗ ███████╗
# ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
# ██████╔╝█████╗  ███████╗   ██║   ██║   ██║██████╔╝█████╗  
# ██╔══██╗██╔══╝  ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝  
# ██║  ██║███████╗███████║   ██║   ╚██████╔╝██║  ██║███████╗
# ╚═╝  ╚═╝╚══════╝╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
// RESTORE TRASHED FILE
##################################################################################################################
   public function restore($id)
   {
      $recipe = Recipe::withTrashed()->findOrFail($id);

      //$article->deleted_at = NULL;
      //$article->save();
      $recipe->restore();

      Session::flash ('success','The recipe was successfully restored.');
      return redirect()->route('recipes.trashed');
   }


##################################################################################################################
# ██████╗ ███████╗███████╗████████╗ ██████╗ ██████╗ ███████╗     █████╗ ██╗     ██╗     
# ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝    ██╔══██╗██║     ██║     
# ██████╔╝█████╗  ███████╗   ██║   ██║   ██║██████╔╝█████╗      ███████║██║     ██║     
# ██╔══██╗██╔══╝  ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝      ██╔══██║██║     ██║     
# ██║  ██║███████╗███████║   ██║   ╚██████╔╝██║  ██║███████╗    ██║  ██║███████╗███████╗
# ╚═╝  ╚═╝╚══════╝╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝    ╚═╝  ╚═╝╚══════╝╚══════╝
// RESTORE ALL TRASHED FILE
##################################################################################################################
   public function restoreAll(Request $request)
   {
      //dd('TEST_RESTORE');
      //dd($request);
      //$this->validate($request, [
      //    'checked' => 'required',
      //]);
      //dd('TEST_RESTORE');

      $checked = $request->input('checked');
      //dd($checked);

      // $article = new Article();
      // $article->restore($checked);
      Recipe::whereIn('id', $checked)->restore();

      Session::flash('success','The recipes were restored successfully.');
      return redirect()->route('recipes.trashed');
   }


##################################################################################################################
# ███████╗██╗  ██╗ ██████╗ ██╗    ██╗
# ██╔════╝██║  ██║██╔═══██╗██║    ██║
# ███████╗███████║██║   ██║██║ █╗ ██║
# ╚════██║██╔══██║██║   ██║██║███╗██║
# ███████║██║  ██║╚██████╔╝╚███╔███╔╝
# ╚══════╝╚═╝  ╚═╝ ╚═════╝  ╚══╝╚══╝ 
// Display the specified resource
##################################################################################################################
   public function show($id)
   {
      $recipe = Recipe::find($id);

      // Set the variable so we can use a button in other pages to come back to this page
      Session::put('fullURL', \Request::fullUrl());

      // get previous recipe id
      $previous = Recipe::published()->where('id', '<', $recipe->id)->max('id');

      // get next recipe id
      $next = Recipe::published()->where('id', '>', $recipe->id)->min('id');

      // Add 1 to views column
      DB::table('recipes')->where('id','=',$recipe->id)->increment('views',1);

      // If user is logged in, update the last_viewed_by_id and last_viewed_on fields in the recipes table
      // if (Auth::check()) {
      //    DB::statement("UPDATE recipes SET last_viewed_by_id = " . Auth::user()->id . " where id = " . $id );
      //    DB::statement("UPDATE recipes SET last_viewed_on = " . DB::raw('NOW()') . " where id = " . $id );
      // }

      // Get list of recips by year and month
      $recipelinks = DB::table('recipes')
         ->select(DB::raw('YEAR(published_at) year, MONTH(published_at) month, MONTHNAME(published_at) month_name, COUNT(*) recipe_count'))
         ->where('published_at', '<=', Carbon::now())
         //->subMonth(3)) --Only show the last 3 months
         //->whereRaw('published = 1') -- field no longer used
         ->groupBy('year')
         ->groupBy('month')
         ->orderBy('year', 'desc')
         ->orderBy('month', 'desc')
         ->get();

      // Save entry to log file using built-in Monolog
      if (Auth::check()) {
         //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") viewed :: Recipe (" . $recipe->id . ")");
      } else {
         //Log::info(getClientIP() . " viewed :: Recipe (" . $recipe->id . ")");
      }

      return view('recipes.show', compact('recipe','recipelinks','next','previous'));
   }


##################################################################################################################
# ███████╗████████╗ ██████╗ ██████╗ ███████╗
# ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
# ███████╗   ██║   ██║   ██║██████╔╝█████╗  
# ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝  
# ███████║   ██║   ╚██████╔╝██║  ██║███████╗
# ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
// Store a newly created resource in storage
##################################################################################################################
   public function store(CreateRecipeRequest $request)
   {
      // if(!checkACL('author')) {
      //     return view('errors.403');
      // }

      $recipe = new Recipe;
         $recipe->title = $request->title;
         $recipe->ingredients = Purifier::clean($request->ingredients);
         $recipe->methodology = Purifier::clean($request->methodology);
         $recipe->category_id = $request->category_id;
         $recipe->published_at = $request->published_at;
         $recipe->servings = $request->servings;
         $recipe->prep_time = $request->prep_time;
         $recipe->cook_time = $request->cook_time;
         $recipe->personal = $request->personal;
         $recipe->source = $request->source;
         $recipe->author_notes = $request->author_notes;
         $recipe->public_notes = $request->public_notes;
         $recipe->modified_by_id = Auth::user()->id;
         $recipe->last_viewed_by_id = Auth::user()->id;
         $recipe->last_viewed_on = Carbon::Now();
         $recipe->user_id = Auth::user()->id;
      $recipe->save();

      // Save entry to log file using built-in Monolog
      //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") CREATED article (" . $article->id . ")\r\n", [json_decode($article, true)]
      //);

      Session::flash('success','The article has been created successfully!');
      return redirect()->route($request->ref);
   }


##################################################################################################################
# ███████╗████████╗ ██████╗ ██████╗ ███████╗     ██████╗ ██████╗ ███╗   ███╗███╗   ███╗███████╗███╗   ██╗████████╗
# ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝    ██╔════╝██╔═══██╗████╗ ████║████╗ ████║██╔════╝████╗  ██║╚══██╔══╝
# ███████╗   ██║   ██║   ██║██████╔╝█████╗      ██║     ██║   ██║██╔████╔██║██╔████╔██║█████╗  ██╔██╗ ██║   ██║   
# ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝      ██║     ██║   ██║██║╚██╔╝██║██║╚██╔╝██║██╔══╝  ██║╚██╗██║   ██║   
# ███████║   ██║   ╚██████╔╝██║  ██║███████╗    ╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ╚═╝ ██║███████╗██║ ╚████║   ██║   
# ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝     ╚═════╝ ╚═════╝ ╚═╝     ╚═╝╚═╝     ╚═╝╚══════╝╚═╝  ╚═══╝   ╚═╝   
##################################################################################################################
	 public function storeComment(CreateCommentRequest $request, $id)
		  // public function storeComment(Request $request, $id)
	 {
		  //dd($id);
		  $recipe = Recipe::find($id);
		  //dd($project);

		  $comment = new Comment();
				// $comment->name = $request->name;
				// $comment->email = $request->email;
				$comment->user_id = Auth::user()->id;
				$comment->comment = $request->comment;
			$recipe->comments()->save($comment);
		  //$comment->save();

		  // Save entry to log file using built-in Monolog
		  // if (Auth::check()) {
		  //     Log::info(Auth::user()->username . " (" . Auth::user()->id . ") commented on post (" . $post->id . ")\r\n", [json_decode($comment, true)]);
		  // } else {
		  //     Log::info(Request::ip() . " commented on post " . $post->id);
		  // }

		  Session::flash('success', 'Comment added succesfully.');
		  return redirect()->route('recipes.show', $recipe->id);
	 }


##################################################################################################################
# ████████╗██████╗  █████╗ ███████╗██╗  ██╗███████╗██████╗ 
# ╚══██╔══╝██╔══██╗██╔══██╗██╔════╝██║  ██║██╔════╝██╔══██╗
#    ██║   ██████╔╝███████║███████╗███████║█████╗  ██║  ██║
#    ██║   ██╔══██╗██╔══██║╚════██║██╔══██║██╔══╝  ██║  ██║
#    ██║   ██║  ██║██║  ██║███████║██║  ██║███████╗██████╔╝
#    ╚═╝   ╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝╚══════╝╚═════╝ 
// Display a list of resources that have been trashed (Soft Deleted)
##################################################################################################################
   public function trashed(Request $request)
   {
      // if(!checkACL('guest')) {
      //     return view('errors.403');
      // }

      $recipes = Recipe::with('user','category')->onlyTrashed()->get();
      return view('recipes.trashed', compact('recipes'));
   }


##################################################################################################################
# ████████╗██████╗  █████╗ ███████╗██╗  ██╗     █████╗ ██╗     ██╗     
# ╚══██╔══╝██╔══██╗██╔══██╗██╔════╝██║  ██║    ██╔══██╗██║     ██║     
#    ██║   ██████╔╝███████║███████╗███████║    ███████║██║     ██║     
#    ██║   ██╔══██╗██╔══██║╚════██║██╔══██║    ██╔══██║██║     ██║     
#    ██║   ██║  ██║██║  ██║███████║██║  ██║    ██║  ██║███████╗███████╗
#    ╚═╝   ╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝    ╚═╝  ╚═╝╚══════╝╚══════╝
// Remove the specified resource from storage
// Used in the index page to soft delete multiple records
##################################################################################################################
   public function trashAll(Request $request)
   {
      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      $this->validate($request, [
         'checked' => 'required',
      ]);

      $checked = $request->input('checked');
      //dd($checked);

      Recipe::destroy($checked);

      Session::flash('success','The recipes were trashed successfully.');
      return redirect()->route($ref);
   }


##################################################################################################################
# ██╗   ██╗███╗   ██╗██████╗ ██╗   ██╗██████╗ ██╗     ██╗███████╗██╗  ██╗
# ██║   ██║████╗  ██║██╔══██╗██║   ██║██╔══██╗██║     ██║██╔════╝██║  ██║
# ██║   ██║██╔██╗ ██║██████╔╝██║   ██║██████╔╝██║     ██║███████╗███████║
# ██║   ██║██║╚██╗██║██╔═══╝ ██║   ██║██╔══██╗██║     ██║╚════██║██╔══██║
# ╚██████╔╝██║ ╚████║██║     ╚██████╔╝██████╔╝███████╗██║███████║██║  ██║
#  ╚═════╝ ╚═╝  ╚═══╝╚═╝      ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚══════╝╚═╝  ╚═╝
##################################################################################################################
   public function unpublish($id)
   {
      // Pass along the ROUTE value of the previous page
      //$ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      $recipe = Recipe::find($id);
         $recipe->published_at = NULL;
         // $article->favoriteArticles()->delete(); // Remove associated rows from article_user (favorites table)
        
         $favorites = DB::select('select * from recipe_user where recipe_id = '. $id, [1]);
         //dd ($favorites);
         foreach($favorites as $favorite) {
            //dd($favorite);
            $recipe->favorites()->detach($favorite);
         }
      $recipe->save();

      Session::flash ('success','The recipe was successfully unpublished.');
      //return redirect()->route($ref);
      return redirect()->route('recipes.show', $id);
   }


##################################################################################################################
# ██╗   ██╗███╗   ██╗██████╗ ██╗   ██╗██████╗ ██╗     ██╗███████╗██╗  ██╗███████╗██████╗ 
# ██║   ██║████╗  ██║██╔══██╗██║   ██║██╔══██╗██║     ██║██╔════╝██║  ██║██╔════╝██╔══██╗
# ██║   ██║██╔██╗ ██║██████╔╝██║   ██║██████╔╝██║     ██║███████╗███████║█████╗  ██║  ██║
# ██║   ██║██║╚██╗██║██╔═══╝ ██║   ██║██╔══██╗██║     ██║╚════██║██╔══██║██╔══╝  ██║  ██║
# ╚██████╔╝██║ ╚████║██║     ╚██████╔╝██████╔╝███████╗██║███████║██║  ██║███████╗██████╔╝
#  ╚═════╝ ╚═╝  ╚═══╝╚═╝      ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚══════╝╚═╝  ╚═╝╚══════╝╚═════╝ 
// Display a list of resources that have not been published
##################################################################################################################
   public function unpublished(Request $request, $key=null)
   {
      if(!checkACL('editor')) {
          return view('errors.403');
      }

      // Set the variable so we can use a button in other pages to come back to this page
      Session::put('backURL', Route::currentRouteName());

      //$alphas = range('A', 'Z');
        $alphas = DB::table('recipes')
         ->select(DB::raw('DISTINCT LEFT(title, 1) as letter'))
         // ->where('personal', '!=', 1)
         ->where('published_at','=', null)
         ->orderBy('letter')
         ->get();
         //dd($alphas);

      $letters = [];
      foreach($alphas as $alpha) {
         $letters[] = $alpha->letter;
      }

      // If $key value is passed
      if ($key) {
         $recipes = Recipe::with('user','category')->unpublished()
            ->where('title', 'like', $key . '%')
            ->orderBy('title', 'asc')
            ->get();
         return view('recipes.unpublished', compact('recipes','letters'));
      }

      // No $key value is passed
      $recipes = Recipe::with('user','category')->unpublished()->get();
      return view('recipes.unpublished', compact('recipes','letters'));
   }


##################################################################################################################
# ██╗   ██╗███╗   ██╗██████╗ ██╗   ██╗██████╗ ██╗     ██╗███████╗██╗  ██╗     █████╗ ██╗     ██╗     
# ██║   ██║████╗  ██║██╔══██╗██║   ██║██╔══██╗██║     ██║██╔════╝██║  ██║    ██╔══██╗██║     ██║     
# ██║   ██║██╔██╗ ██║██████╔╝██║   ██║██████╔╝██║     ██║███████╗███████║    ███████║██║     ██║     
# ██║   ██║██║╚██╗██║██╔═══╝ ██║   ██║██╔══██╗██║     ██║╚════██║██╔══██║    ██╔══██║██║     ██║     
# ╚██████╔╝██║ ╚████║██║     ╚██████╔╝██████╔╝███████╗██║███████║██║  ██║    ██║  ██║███████╗███████╗
#  ╚═════╝ ╚═╝  ╚═══╝╚═╝      ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚══════╝╚═╝  ╚═╝    ╚═╝  ╚═╝╚══════╝╚══════╝
##################################################################################################################
   public function unpublishAll(Request $request)
   {
      // Pass along the ROUTE value of the previous page
      $ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

      $this->validate($request, [
         'checked' => 'required',
      ]);

      $checked = $request->input('checked');

      foreach ($checked as $item) {
         //dd($item);
         $recipe = Recipe::withTrashed()->find($item);
            $recipe->published_at = Null;

            // Delete related favorites
            $favorites = DB::select('select * from recipe_user where recipe_id = '. $recipe->id, [1]);
               foreach($favorites as $favorite) {
                  $recipe->favoriteRecipes()->detach($favorite);
               }
         $recipe->save();
      }
      

      Session::flash('success','The recipes were published successfully.');
      return redirect()->route($ref);
   }


##################################################################################################################
# ██╗   ██╗██████╗ ██████╗  █████╗ ████████╗███████╗
# ██║   ██║██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██╔════╝
# ██║   ██║██████╔╝██║  ██║███████║   ██║   █████╗  
# ██║   ██║██╔═══╝ ██║  ██║██╔══██║   ██║   ██╔══╝  
# ╚██████╔╝██║     ██████╔╝██║  ██║   ██║   ███████╗
#  ╚═════╝ ╚═╝     ╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚══════╝
// UPDATE :: Update the specified resource in storage
##################################################################################################################
   public function update(UpdateRecipeRequest $request, $id)
   {
      // Get the recipe values from the database
      $recipe = Recipe::find($id);

      // save the data in the database
      $recipe->title = $request->title;
      $recipe->ingredients = Purifier::clean($request->ingredients);
      $recipe->methodology = Purifier::clean($request->methodology);
      $recipe->category_id = $request->category_id;
      $recipe->published_at = $request->published_at;
      $recipe->servings = $request->servings;
      $recipe->prep_time = $request->prep_time;
      $recipe->cook_time = $request->cook_time;
      $recipe->personal = $request->personal;
      $recipe->source = $request->source;
      $recipe->author_notes = $request->author_notes;
      $recipe->public_notes = $request->public_notes;
      $recipe->modified_by_id = Auth::user()->id;
      $recipe->last_viewed_by_id = Auth::user()->id;
      $recipe->last_viewed_on = Carbon::Now();

      // Check if a new image was submitted
      if ($request->hasFile('image')) {
         //Add new photo
         $image = $request->file('image');
         $filename = time() . '.' . $image->getClientOriginalExtension();
         $location = public_path('_recipes/' . $filename);
         Image::make($image)->resize(800, 400)->save($location);

         // get name of old image
         $oldImageName = $recipe->image;
         //dd($oldImageName);

         // Update database
         $recipe->image = $filename;

         // Delete old photo
         //Storage::delete($oldImageName);
         File::delete('_recipes/'.$oldImageName);
      }

      $recipe->save();

      // Save entry to log file using built-in Monolog
      //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") updated :: Recipe (" . $recipe->id .")");

      // set a flash message to be displayed on screen
      Session::flash('success','The recipe was successfully updated!');
      // redirect to another page
      //return redirect()->route('recipes.index');
      return redirect(Session::get('fullURL'));
  }


}
<file_sep><?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class CreateWoodProjectRequest extends Request
{
	/**
	 * Determine if the user is authorized to make this request.
	 *
	 * @return bool
	 */
	public function authorize()
	{
		return true;
	}

	/**
	 * Get the validation rules that apply to the request.
	 *
	 * @return array
	 */
	public function rules()
	{
		// https://laravel.com/docs/5.2/validation#available-validation-rules
		return [
			'name'          => 'required',
			'description'   => 'required',
			'category_id'   => 'required',
			'main_image'    => 'required|image|max:1999'
		];
	}

	public function messages()
	{
		return [
			'name.required'             => 'Required',
			'description.required'      => 'Required',
			'category_id.required'      => 'Required',
			'main_image.required'       => 'Required',
			'main_image.image'          => 'Must be an image file',
			'main_image.max'            => 'Cannot be larger than 2MB'
		];
	}

}
<file_sep><?php

namespace App\Http\Controllers;

use DB;
use Session;
use App\Dart;
use App\DartScore;
use App\User;
use Illuminate\Http\Request;

class DartScoresController extends Controller
{
	

	public function teamIndex($gameID)
	{
		$game = Dart::find($gameID);
		return view('darts.01.teamScores.index', compact('game'));
	}


	// public function playerIndex($gameID)
	// {
	// 	$game = Dart::find($gameID);
	// 	return view('darts.01.playerScores.index', compact('game'));
	// }


	// public function cricketTeamIndex($gameID)
	// {
	// 	$game = Dart::find($gameID);
	// 	return view('darts.cricket.teamScores.index', compact('game'));
	// }


	// public function cricketPlayerIndex($gameID)
	// {
	// 	$game = Dart::find($gameID);
	// 	return view('darts.cricket.playerScores.index', compact('game'));
	// }


	public function create()
	{
		//
	}

##################################################################################################################
# ███████╗████████╗ ██████╗ ██████╗ ███████╗
# ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
# ███████╗   ██║   ██║   ██║██████╔╝█████╗  
# ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝  
# ███████║   ██║   ╚██████╔╝██║  ██║███████╗
# ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
##################################################################################################################
	public function teamStore(Request $request)
	{
		// if(!checkACL('manager')) {
		//   return view('errors.403');
		// }

		$this->validate($request, [
			'game_id' => 'required',
			'team_id' => 'required',
			'user_id' => 'required',
			'score1' => 'sometimes|required|integer|max:180',
			'score2' => 'sometimes|required|integer|max:180'
		],
		[
			'user_id.required' => 'Please select a player.',
			'score1.required' => 'Please enter a score.',
			'score1.integer' => 'Score must be a number.',
			'score1.max' => 'Score must be less than 181.',
			'score2.required' => 'Please enter a score.',
			'score2.integer' => 'Score must be a number.',
			'score2.max' => 'Score must be less than 181.',
		]);

		// Determine which score box has data
		if($request->score1) {
			$whichScore = $request->score1;
		}else{
			$whichScore = $request->score2;
		}

		// Is the entered score less than 0?
		if($whichScore < 0){
			Session::flash('error','Invalid Score! You need to enter a score above 0. Please try again.');
			return redirect()->route('darts.01.teamScores.index', $request->game_id);
		}

		// Is the entered score greater than 180?
		if($whichScore > 180){
			Session::flash('error','Invalid Score! Total score cannot exceed 180. Please try again.');
			return redirect()->route('darts.01.teamScores.index', $request->game_id);
		}

		// Would the entered score leave 1 remaining which is not possible
		if($request->remainingScore - $whichScore == 1){
			$score = new DartScore;
				$score->user_id = $request->user_id;
				$score->team_id = $request->team_id;
				$score->game_id = $request->game_id;
				$score->score = 0;
				$score->remaining = $request->remainingScore;
			$score->save();

			Session::flash('error','This score cannot be registered as it would leave an impossibility to finish with a Double Out. A value of 0 will be added to the scoresheet.');
			return redirect()->route('darts.01.teamScores.index', $request->game_id);
		}

		// Is the entered score greater than the remaining score?
		if($whichScore > $request->remainingScore){
			$score = new DartScore;
				$score->user_id = $request->user_id;
				$score->team_id = $request->team_id;
				$score->game_id = $request->game_id;
				$score->score = 0;
				$score->remaining = $request->remainingScore;
			$score->save();

			Session::flash('error','The registered score is higher than the required score to finish. A value of 0 will be added to the scoresheet.');
			return redirect()->route('darts.01.teamScores.index', $request->game_id);
		}

		// All checks passed, enter the score in the DB
		$score = new DartScore;
			$score->user_id = $request->user_id;
			$score->team_id = $request->team_id;
			$score->game_id = $request->game_id;
			$score->score = $whichScore;
			$score->remaining = $request->remainingScore - $whichScore;
		$score->save();

		// Change the game status to In Progress 
		$game = Dart::find($request->game_id);
			$game->status = 'In Progress';
		$game->save();

		if(gameWinner($game) == true) {
			$game = Dart::find($request->game_id);
				$game->status = 'Completed';
			$game->save();
			echo 'Qwerty';
		}


		// Save entry to log file using built-in Monolog
		//Log::info(Auth::user()->username . " (" . Auth::user()->id . ") CREATED category (" . $category->id . ")\r\n", [$category = json_decode($category, true)]);

		Session::flash('success','The scoresheet has been updated.');
		return redirect()->route('darts.01.teamScores.index', $request->game_id);
	}



	public function edit($id)
	{
		//
	}


	public function update(Request $request, $id)
	{
		//
	}


	public function destroy($id)
	{
		//
	}



}
<file_sep><?php

// ITEMS
// Route::group(['namespace' => 'Backend'], function() {
   //Route::get('/backend/items/import',          'Backend\ItemsController@getImport')->name('backend.items.import');
   //Route::post('/backend/items/import_parse',   'Backend\ItemsController@parseImport')->name('backend.items.import_parse');
   //Route::post('/backend/items/import_process', 'Backend\ItemsController@processImport')->name('backend.items.import_process');

   // Route::resource('items', 'Backend\ItemsController');
   //Route::get('backend/items',        'Backend\ItemsController@index')->name('backend.items.index');
// });


// Route::group(['prefix' => 'backend', 'namespace' => 'Backend'], function () {
//    Route::get('items/import', 'ItemsController@getImport')->name('items.import');
//    Route::post('items/import_parse', 'ItemsController@parseImport')->name('items.import_parse');
//    Route::post('items/import_process', 'ItemsController@processImport')->name('items.import_process');

//    Route::get('items/published', 'ItemsController@published')->name('items.published');
//    Route::get('items/unpublished', 'ItemsController@unpublished')->name('items.unpublished');
//    Route::get('items/future', 'ItemsController@future')->name('items.future');
//    Route::get('items/trashed', 'ItemsController@trashed')->name('items.trashed');
   
//    Route::resource('items', 'ItemsController');
// });

Route::resource('items', 'ItemsController');<file_sep><?php

namespace App;

use Illuminate\Database\Eloquent\Model;
//use OwenIt\Auditing\Auditable;
//use OwenIt\Auditing\Contracts\Auditable as AuditableContract;
use Auth;

class Module extends Model //implements AuditableContract
{
	//use Auditable;
	
	/**
	* Always capitalize the first name when we retrieve it
	*/
	public function getNameAttribute($value) {
		return ucfirst($value);
	}

   public function scopeNewModules($query)
   {
      return $query
         ->where('created_at', '>=' , Auth::user()->last_login_date)
         //->where('user_id', '=', Auth::user()->id)
         ->orderBy('name','DESC');
   }

}
<file_sep><?php

use Illuminate\Database\Seeder;


class UsersTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('users')->insert([
            'id' => 1,
            'username' => 'admin',
            'role_id' => 10,
            'email' => '<EMAIL>',
            'password' => bcrypt('<PASSWORD>'),
        ]);

        DB::table('users')->insert([
            'id' => 2,
            'username' => 'lerouxs',
            'role_id' => 20,
            'public_email' => 1,
            'email' => '<EMAIL>',
            'password' => bcrypt('<PASSWORD>'),
        ]);

        DB::table('users')->insert([
            'id' => 3,
            'username' => 'hayness',
            'role_id' => 60,
            'email' => '<EMAIL>',
            'password' => bcrypt('<PASSWORD>'),
        ]);

        DB::table('users')->insert([
            'id' => 4,
            'username' => 'lerouxh',
            'role_id' => 60,
            'email' => '<EMAIL>',
            'password' => bcrypt('<PASSWORD>'),
        ]);

        DB::table('users')->insert([
            'id' => 5,
            'username' => 'leveillel',
            'role_id' => 55,
            'email' => '<EMAIL>',
            'password' => bcrypt('<PASSWORD>'),
        ]);
    }
}
<file_sep><?php

namespace App\Http\Controllers\Backend;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Controller;

use Illuminate\Support\Facades\Input;
use App\Article;
use App\Category;
use App\User;
use Auth;
use Carbon\Carbon;
use DB;
use Excel;
use Log;
use PDF;
use Session;
use Table;
use URL;
use View;

use App\Http\Requests\CreateArticleRequest;
use App\Http\Requests\UpdateArticleRequest;

class ArticlesController extends Controller
{

##################################################################################################################
#  ██████╗ ██████╗ ███╗   ██╗███████╗████████╗██████╗ ██╗   ██╗ ██████╗████████╗
# ██╔════╝██╔═══██╗████╗  ██║██╔════╝╚══██╔══╝██╔══██╗██║   ██║██╔════╝╚══██╔══╝
# ██║     ██║   ██║██╔██╗ ██║███████╗   ██║   ██████╔╝██║   ██║██║        ██║   
# ██║     ██║   ██║██║╚██╗██║╚════██║   ██║   ██╔══██╗██║   ██║██║        ██║   
# ╚██████╗╚██████╔╝██║ ╚████║███████║   ██║   ██║  ██║╚██████╔╝╚██████╗   ██║   
#  ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝  ╚═════╝   ╚═╝   
##################################################################################################################
	public function __construct() {
		// only allow authenticated users to access these pages
		//$this->middleware('auth', ['except'=>['index','show']]);
		// changing auth to guest would only allow guests to access these pages
		// you can also restrict the actions by adding ['except' => 'name_of_action'] at the end
		$this->middleware('auth');

		//Log::useFiles(storage_path().'/logs/articles.log');
		//Log::useFiles(storage_path().'/logs/audits.log');
	}


##################################################################################################################
#  █████╗ ██████╗ ██████╗     ███████╗ █████╗ ██╗   ██╗ ██████╗ ██████╗ ██╗████████╗███████╗
# ██╔══██╗██╔══██╗██╔══██╗    ██╔════╝██╔══██╗██║   ██║██╔═══██╗██╔══██╗██║╚══██╔══╝██╔════╝
# ███████║██║  ██║██║  ██║    █████╗  ███████║██║   ██║██║   ██║██████╔╝██║   ██║   █████╗  
# ██╔══██║██║  ██║██║  ██║    ██╔══╝  ██╔══██║╚██╗ ██╔╝██║   ██║██╔══██╗██║   ██║   ██╔══╝  
# ██║  ██║██████╔╝██████╔╝    ██║     ██║  ██║ ╚████╔╝ ╚██████╔╝██║  ██║██║   ██║   ███████╗
# ╚═╝  ╚═╝╚═════╝ ╚═════╝     ╚═╝     ╚═╝  ╚═╝  ╚═══╝   ╚═════╝ ╚═╝  ╚═╝╚═╝   ╚═╝   ╚══════╝
##################################################################################################################
	public function addfavorite($id)
	{
		// Pass along the ROUTE value of the previous page
		$ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

		$user = Auth::user()->id;
		$article = Article::find($id);

		$article->favorites()->sync([$user], false);

		Session::flash ('success','The article was successfully added to your Favorites list!');
		// return redirect()->route('backend.articles.index');
		// return redirect()->route($ref);
		return redirect()->back()->withRef($ref);
	}


##################################################################################################################
#  ██████╗██████╗ ███████╗ █████╗ ████████╗███████╗
# ██╔════╝██╔══██╗██╔════╝██╔══██╗╚══██╔══╝██╔════╝
# ██║     ██████╔╝█████╗  ███████║   ██║   █████╗  
# ██║     ██╔══██╗██╔══╝  ██╔══██║   ██║   ██╔══╝  
# ╚██████╗██║  ██║███████╗██║  ██║   ██║   ███████╗
#  ╚═════╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝   ╚═╝   ╚══════╝
// Show the form for creating a new resource
##################################################################################################################
	public function create()
	{
		if(!checkACL('author')) {
		    return view('errors.backend.403');
		}

		// Pass along the ROUTE value of the previous page
		//$ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

		// find all categories in the categories table and pass them to the view
		$categories = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'articles');
		})->orderBy('name','asc')->get();

		// Create an empty array to store the categories
		$cats = [];

		// Store the category values into the $cats array
		foreach ($categories as $category) {
			$cats[$category->id] = $category->name;
		}

		return view('backend.articles.create')->withCategories($cats);
		//->withRef($ref);
	}


##################################################################################################################
# ██████╗ ███████╗██╗     ███████╗████████╗███████╗     █████╗ ██╗     ██╗     
# ██╔══██╗██╔════╝██║     ██╔════╝╚══██╔══╝██╔════╝    ██╔══██╗██║     ██║     
# ██║  ██║█████╗  ██║     █████╗     ██║   █████╗      ███████║██║     ██║     
# ██║  ██║██╔══╝  ██║     ██╔══╝     ██║   ██╔══╝      ██╔══██║██║     ██║     
# ██████╔╝███████╗███████╗███████╗   ██║   ███████╗    ██║  ██║███████╗███████╗
# ╚═════╝ ╚══════╝╚══════╝╚══════╝   ╚═╝   ╚══════╝    ╚═╝  ╚═╝╚══════╝╚══════╝
// Mass Delete selected rows - all selected records
##################################################################################################################
	public function deleteAll(Request $request)
	{
		// Pass along the ROUTE value of the previous page
		$ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

		//dd('TEST_DELETE');
		$this->validate($request, [
			'checked' => 'required',
		]);
		//dd('TEST_DELETE');

		$checked = $request->input('checked');
		//dd($checked);

		// $article = Article::withTrashed()->findOrFail($checked);
		//Article::destroy($checked);
		Article::whereIn('id', $checked)->forceDelete();

		Session::flash('success','The articles were deleted successfully.');
		return redirect()->route($ref);
	}


##################################################################################################################
# ██████╗ ███████╗██╗     ███████╗████████╗███████╗    ████████╗██████╗  █████╗ ███████╗██╗  ██╗███████╗██████╗ 
# ██╔══██╗██╔════╝██║     ██╔════╝╚══██╔══╝██╔════╝    ╚══██╔══╝██╔══██╗██╔══██╗██╔════╝██║  ██║██╔════╝██╔══██╗
# ██║  ██║█████╗  ██║     █████╗     ██║   █████╗         ██║   ██████╔╝███████║███████╗███████║█████╗  ██║  ██║
# ██║  ██║██╔══╝  ██║     ██╔══╝     ██║   ██╔══╝         ██║   ██╔══██╗██╔══██║╚════██║██╔══██║██╔══╝  ██║  ██║
# ██████╔╝███████╗███████╗███████╗   ██║   ███████╗       ██║   ██║  ██║██║  ██║███████║██║  ██║███████╗██████╔╝
# ╚═════╝ ╚══════╝╚══════╝╚══════╝   ╚═╝   ╚══════╝       ╚═╝   ╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝╚══════╝╚═════╝ 
// Remove the specified resource from storage - individual record
##################################################################################################################
	public static function deleteTrashed($id)
	{
		// if(!checkACL('manager')) {
			// return view('errors.403');
		// }
		//dd($id);
		$article = Article::withTrashed()->findorFail($id);
		//dd($article);
		$article->forceDelete();

		Session::flash ('success','The article was deleted successfully.');
		return redirect()->route('backend.articles.trashed');
	}


##################################################################################################################
# ██████╗ ███████╗███████╗████████╗██████╗  ██████╗ ██╗   ██╗
# ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔══██╗██╔═══██╗╚██╗ ██╔╝
# ██║  ██║█████╗  ███████╗   ██║   ██████╔╝██║   ██║ ╚████╔╝ 
# ██║  ██║██╔══╝  ╚════██║   ██║   ██╔══██╗██║   ██║  ╚██╔╝  
# ██████╔╝███████╗███████║   ██║   ██║  ██║╚██████╔╝   ██║   
# ╚═════╝ ╚══════╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝    ╚═╝   
// Remove the specified resource from storage
// Used in the index page and trashAll action to soft delete multiple records
##################################################################################################################
	public function destroy($id)
	{
		// if(!checkACL('author')) {
		//     return view('errors.403');
		// }

		// Pass along the ROUTE value of the previous page
		$ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

		$article = Article::findOrFail($id);
			$article->published_at = Null;
				// Delete related favorites
				$favorites = DB::select('select * from article_user where article_id = '. $id, [1]);
				//dd($favorites);
				  foreach($favorites as $favorite) {
					$article->favorites()->detach($favorite);
				  }
			$article->save();
		$article->delete();

		// Save entry to log file using built-in Monolog
		//Log::info(Auth::user()->username . " (" . Auth::user()->id . ") DELETED article (" . $article->id . ")\r\n",
		//    [json_decode($article, true)]
		//);

		Session::flash('success','The article was trashed successfully.');
		//return redirect()->route($ref);
		//return redirect()->route($request->ref);
		//return redirect()->route('backend.articles.index');
		return redirect()->back();
	}


##################################################################################################################
# ██████╗  ██████╗ ██╗    ██╗███╗   ██╗██╗      ██████╗  █████╗ ██████╗     ███████╗██╗  ██╗ ██████╗███████╗██╗     
# ██╔══██╗██╔═══██╗██║    ██║████╗  ██║██║     ██╔═══██╗██╔══██╗██╔══██╗    ██╔════╝╚██╗██╔╝██╔════╝██╔════╝██║     
# ██║  ██║██║   ██║██║ █╗ ██║██╔██╗ ██║██║     ██║   ██║███████║██║  ██║    █████╗   ╚███╔╝ ██║     █████╗  ██║     
# ██║  ██║██║   ██║██║███╗██║██║╚██╗██║██║     ██║   ██║██╔══██║██║  ██║    ██╔══╝   ██╔██╗ ██║     ██╔══╝  ██║     
# ██████╔╝╚██████╔╝╚███╔███╔╝██║ ╚████║███████╗╚██████╔╝██║  ██║██████╔╝    ███████╗██╔╝ ██╗╚██████╗███████╗███████╗
# ╚═════╝  ╚═════╝  ╚══╝╚══╝ ╚═╝  ╚═══╝╚══════╝ ╚═════╝ ╚═╝  ╚═╝╚═════╝     ╚══════╝╚═╝  ╚═╝ ╚═════╝╚══════╝╚══════╝
##################################################################################################################
	public function downloadExcel($type)
	{
		if(!checkACL('manager')) {
			return view('errors.backend.403');
		}

		if(app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName() == 'backend.articles.newArticles') {
				$data = Article::newArticles()->get()->toArray();
		}
		if(app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName() == 'backend.articles.published') {
				$data = Article::published()->get()->toArray();
		}
		if(app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName() == 'backend.articles.myArticles') {
				$data = Article::myArticles()->get()->toArray();
		}
		if(app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName() == 'backend.articles.unpublished') {
				$data = Article::unpublished()->get()->toArray();
		}
		if(app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName() == 'backend.articles.future') {
				$data = Article::future()->get()->toArray();
		}
		if(app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName() == 'backend.articles.trashed') {
				$data = Article::trashedCount()->get()->toArray();
		}

		// $referrer = request()->headers->get('referer');
		// //dd($referrer);
		// if ($referrer == 'http://localhost:8000/backend/articles/myArticles') {
		// 	$data = Article::myArticles()->get()->toArray();
		// } elseif ($referrer == 'http://localhost:8000/backend/articles/published'){
		//    $data = Article::published()->get()->toArray();
		// } else {
		// 	$data = Article::get()->toArray();
		// }

		// Save entry to log file of failure
		//Log::info(Auth::user()->username . " (" . Auth::user()->id . ") downloaded :: articles");

		return Excel::create('Articles_List', function($excel) use ($data) {
			$excel->sheet('mySheet', function($sheet) use ($data)
			{
				$sheet->fromArray($data);
			});
		})->download($type);
	}


##################################################################################################################
# ██████╗ ██╗   ██╗██████╗ ██╗     ██╗ ██████╗ █████╗ ████████╗███████╗
# ██╔══██╗██║   ██║██╔══██╗██║     ██║██╔════╝██╔══██╗╚══██╔══╝██╔════╝
# ██║  ██║██║   ██║██████╔╝██║     ██║██║     ███████║   ██║   █████╗  
# ██║  ██║██║   ██║██╔═══╝ ██║     ██║██║     ██╔══██║   ██║   ██╔══╝  
# ██████╔╝╚██████╔╝██║     ███████╗██║╚██████╗██║  ██║   ██║   ███████╗
# ╚═════╝  ╚═════╝ ╚═╝     ╚══════╝╚═╝ ╚═════╝╚═╝  ╚═╝   ╚═╝   ╚══════╝
// DUPLICATE :: Duplicate the specified resource in storage.
##################################################################################################################
	public function duplicate($id)
	{
		//if(!checkACL('manager')) {
		//  // Save entry to log file of failure
		//  Log::warning(Auth::user()->username . " (" . Auth::user()->id . ") tried to access :: Articles / Duplicate");
		//  return view('errors.403');
		//}

		// Pass along the ROUTE value of the previous page
		$ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

		$article = Article::find($id);
		  $newArticle = $article->replicate();
		  $newArticle->user_id = Auth::user()->id;
		$newArticle->save();

		// change the user_id field to be that of the user that is currently logged in
		
		//$newArticle->views = 0;
		//$newArticle->save();

		// Save entry to log file using built-in Monolog
		//Log::info(Auth::user()->username . " (" . Auth::user()->id . ") duplicated :: article " . $article->id . " to article ". $newArticle->id);

		Session::flash ('success','The article was duplicated successfully!');
		return redirect()->route($ref);
	}


##################################################################################################################
# ███████╗██████╗ ██╗████████╗
# ██╔════╝██╔══██╗██║╚══██╔══╝
# █████╗  ██║  ██║██║   ██║   
# ██╔══╝  ██║  ██║██║   ██║   
# ███████╗██████╔╝██║   ██║   
# ╚══════╝╚═════╝ ╚═╝   ╚═╝   
// Show the form for editing the specified resource
##################################################################################################################
	public function edit($id)
	{
		if(!checkACL('author')) {
			return view('errors.backend.403');
		}

		// Find the article to edit
		$article = Article::findOrFail($id);

		// find all categories in the categories table and pass them to the view
		$categories = Category::whereHas('module', function ($query) {
			$query->where('name', '=', 'articles');
		})->get();

		// Create an empty array to store the categories
		$cats = [];
		// Store the category values into the $cats array
		foreach ($categories as $category) {
			$cats[$category->id] = $category->name;
		}

		return view('backend.articles.edit', compact('article'))
		   ->withCategories($cats);
	}


##################################################################################################################
# ███████╗██╗   ██╗████████╗██╗   ██╗██████╗ ███████╗
# ██╔════╝██║   ██║╚══██╔══╝██║   ██║██╔══██╗██╔════╝
# █████╗  ██║   ██║   ██║   ██║   ██║██████╔╝█████╗  
# ██╔══╝  ██║   ██║   ██║   ██║   ██║██╔══██╗██╔══╝  
# ██║     ╚██████╔╝   ██║   ╚██████╔╝██║  ██║███████╗
# ╚═╝      ╚═════╝    ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
// Display a list of resources that will be published at a later date
##################################################################################################################
	public function future(Request $request, $key=null)
	{
		if(!checkACL('publisher')) {
			return view('errors.backend.403');
		}

		//$alphas = range('A', 'Z');
		$alphas = DB::table('articles')
			->select(DB::raw('DISTINCT LEFT(title, 1) as letter'))
			// ->where('personal', '!=', 1)
			->where('published_at','>', Carbon::Now())
			->orderBy('letter')
			->get();
			//dd($alphas);

		$letters = [];
		foreach($alphas as $alpha) {
			$letters[] = $alpha->letter;
		}

		// If $key value is passed
		if ($key) {
			$articles = Article::with('user','category')->future()
				->where('title', 'like', $key . '%')
				->orderBy('title', 'asc')
				->get();
			return view('backend.articles.future', compact('articles','letters'));
		}

		// No $key value is passed
		$articles = Article::with('user','category')->future()->get();
		return view('backend.articles.future', compact('articles','letters'));
	}


##################################################################################################################
# ██╗███╗   ███╗██████╗  ██████╗ ██████╗ ████████╗
# ██║████╗ ████║██╔══██╗██╔═══██╗██╔══██╗╚══██╔══╝
# ██║██╔████╔██║██████╔╝██║   ██║██████╔╝   ██║   
# ██║██║╚██╔╝██║██╔═══╝ ██║   ██║██╔══██╗   ██║   
# ██║██║ ╚═╝ ██║██║     ╚██████╔╝██║  ██║   ██║   
# ╚═╝╚═╝     ╚═╝╚═╝      ╚═════╝ ╚═╝  ╚═╝   ╚═╝   
// IMPORT :: Show the form for importing entries to storage.
##################################################################################################################
	public function import()
	{
		if(!checkACL('manager')) {
			return view('errors.backend.403');
		}

		// Pass along the ROUTE value of the previous page
		$ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

		// Save entry to log file of failure
		//Log::warning(Auth::user()->username . " (" . Auth::user()->id . ") accessed :: Articles / Import");

		return view('backend.articles.import')->withRef($ref);
	}


##################################################################################################################
# ██╗███╗   ███╗██████╗  ██████╗ ██████╗ ████████╗    ███████╗██╗   ██╗███╗   ██╗ ██████╗████████╗██╗ ██████╗ ███╗   ██╗
# ██║████╗ ████║██╔══██╗██╔═══██╗██╔══██╗╚══██╔══╝    ██╔════╝██║   ██║████╗  ██║██╔════╝╚══██╔══╝██║██╔═══██╗████╗  ██║
# ██║██╔████╔██║██████╔╝██║   ██║██████╔╝   ██║       █████╗  ██║   ██║██╔██╗ ██║██║        ██║   ██║██║   ██║██╔██╗ ██║
# ██║██║╚██╔╝██║██╔═══╝ ██║   ██║██╔══██╗   ██║       ██╔══╝  ██║   ██║██║╚██╗██║██║        ██║   ██║██║   ██║██║╚██╗██║
# ██║██║ ╚═╝ ██║██║     ╚██████╔╝██║  ██║   ██║       ██║     ╚██████╔╝██║ ╚████║╚██████╗   ██║   ██║╚██████╔╝██║ ╚████║
# ╚═╝╚═╝     ╚═╝╚═╝      ╚═════╝ ╚═╝  ╚═╝   ╚═╝       ╚═╝      ╚═════╝ ╚═╝  ╚═══╝ ╚═════╝   ╚═╝   ╚═╝ ╚═════╝ ╚═╝  ╚═══╝
##################################################################################################################
	public function importExcel()
	{
		// if(!checkACL('manager')) {
		//   // Save entry to log file of failure
		//   Log::warning(Auth::user()->username . " (" . Auth::user()->id . ") tried to access :: Admin / Articles / Import");
		//   return view('errors.403');
		// }

		if(Input::hasFile('import_file')) {
				$path = Input::file('import_file')->getRealPath();
				$data = Excel::load($path, function($reader) {
			})->get();

			if(!empty($data) && $data->count()) {
				foreach ($data as $key => $value) {
					$insert[] = [
						'user_id'				=> $value->user_id,
						'category_id'			=> $value->category_id,
						'title'					=> $value->title,            
						'description_eng'		=> $value->description_eng,
						'description_fre'		=> $value->description_fre,
						'views'					=>  0,
						'deleted_at'			=> $value->deleted_at,
						'published_at'			=> $value->published_at,
						'created_at'			=> $value->created_at,
						'updated_at'			=> $value->updated_at,
					];
				}

				if(!empty($insert)) {
					DB::table('articles')->insert($insert);

					// Save entry to log file of failure
					//Log::warning(Auth::user()->username . " (" . Auth::user()->id . ") imported :: articles");

					Session::flash('success', $data->count() . ' articles imported successfully!');
					return redirect()->route('backend.articles.index');
				}
			}
		}
		return back();
	}


##################################################################################################################
# ██╗███╗   ██╗██████╗ ███████╗██╗  ██╗
# ██║████╗  ██║██╔══██╗██╔════╝╚██╗██╔╝
# ██║██╔██╗ ██║██║  ██║█████╗   ╚███╔╝ 
# ██║██║╚██╗██║██║  ██║██╔══╝   ██╔██╗ 
# ██║██║ ╚████║██████╔╝███████╗██╔╝ ██╗
# ╚═╝╚═╝  ╚═══╝╚═════╝ ╚══════╝╚═╝  ╚═╝
// Display a list of resources
##################################################################################################################
	public function index() {
		return view('backend.articles.index');
	}


##################################################################################################################
# ███╗   ███╗ █████╗ ██╗  ██╗███████╗    ██████╗ ██████╗ ██╗██╗   ██╗ █████╗ ████████╗███████╗
# ████╗ ████║██╔══██╗██║ ██╔╝██╔════╝    ██╔══██╗██╔══██╗██║██║   ██║██╔══██╗╚══██╔══╝██╔════╝
# ██╔████╔██║███████║█████╔╝ █████╗      ██████╔╝██████╔╝██║██║   ██║███████║   ██║   █████╗  
# ██║╚██╔╝██║██╔══██║██╔═██╗ ██╔══╝      ██╔═══╝ ██╔══██╗██║╚██╗ ██╔╝██╔══██║   ██║   ██╔══╝  
# ██║ ╚═╝ ██║██║  ██║██║  ██╗███████╗    ██║     ██║  ██║██║ ╚████╔╝ ██║  ██║   ██║   ███████╗
# ╚═╝     ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝    ╚═╝     ╚═╝  ╚═╝╚═╝  ╚═══╝  ╚═╝  ╚═╝   ╚═╝   ╚══════╝
##################################################################################################################
	public function makeprivate($id)
	{
		// Pass along the ROUTE value of the previous page
		$ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

		$article = Article::find($id);
			$article->personal = 1;
		$article->save();

		// Save entry to log file using built-in Monolog
		//Log::info(Auth::user()->username . " (" . Auth::user()->id . ") MADE recipe (" . $recipe->id . ") PRIVATE \r\n", [json_decode($recipe, true)]);

		Session::flash('success','The article was made private successfully');
		return redirect()->route($ref);
	}


##################################################################################################################
# ███╗   ███╗██╗   ██╗     █████╗ ██████╗ ████████╗██╗ ██████╗██╗     ███████╗███████╗
# ████╗ ████║╚██╗ ██╔╝    ██╔══██╗██╔══██╗╚══██╔══╝██║██╔════╝██║     ██╔════╝██╔════╝
# ██╔████╔██║ ╚████╔╝     ███████║██████╔╝   ██║   ██║██║     ██║     █████╗  ███████╗
# ██║╚██╔╝██║  ╚██╔╝      ██╔══██║██╔══██╗   ██║   ██║██║     ██║     ██╔══╝  ╚════██║
# ██║ ╚═╝ ██║   ██║       ██║  ██║██║  ██║   ██║   ██║╚██████╗███████╗███████╗███████║
# ╚═╝     ╚═╝   ╚═╝       ╚═╝  ╚═╝╚═╝  ╚═╝   ╚═╝   ╚═╝ ╚═════╝╚══════╝╚══════╝╚══════╝
// Display a listing of the resource that belong to a specific user.
##################################################################################################################
	public function myArticles(Request $request, $key=null)
	{
		if(!checkACL('author')) {
			return view('errors.backend.403');
		}

		//$alphas = range('A', 'Z');
		$alphas = DB::table('articles')
			->select(DB::raw('DISTINCT LEFT(title, 1) as letter'))
			->where('user_id', '=', Auth::user()->id)
			// ->where('personal', '!=', 1)
			// ->where('published_at','!=', null)
			->orderBy('letter')
			->get();
		//dd($alphas);

		$letters = [];
		foreach($alphas as $alpha) {
		  $letters[] = $alpha->letter;
		}

		// If $key value is passed
		if ($key) {
			$articles = Article::with('user','category')->myArticles()
				->where('title', 'like', $key . '%')
				->get();
			return view('backend.articles.myArticles', compact('articles','letters'));
		}

		$articles = Article::with('user','category')->myArticles()->get();
		return view('backend.articles.myArticles', compact('articles','letters'));
	}


##################################################################################################################
# ███╗   ███╗██╗   ██╗    ███████╗ █████╗ ██╗   ██╗ ██████╗ ██████╗ ██╗████████╗███████╗███████╗
# ████╗ ████║╚██╗ ██╔╝    ██╔════╝██╔══██╗██║   ██║██╔═══██╗██╔══██╗██║╚══██╔══╝██╔════╝██╔════╝
# ██╔████╔██║ ╚████╔╝     █████╗  ███████║██║   ██║██║   ██║██████╔╝██║   ██║   █████╗  ███████╗
# ██║╚██╔╝██║  ╚██╔╝      ██╔══╝  ██╔══██║╚██╗ ██╔╝██║   ██║██╔══██╗██║   ██║   ██╔══╝  ╚════██║
# ██║ ╚═╝ ██║   ██║       ██║     ██║  ██║ ╚████╔╝ ╚██████╔╝██║  ██║██║   ██║   ███████╗███████║
# ╚═╝     ╚═╝   ╚═╝       ╚═╝     ╚═╝  ╚═╝  ╚═══╝   ╚═════╝ ╚═╝  ╚═╝╚═╝   ╚═╝   ╚══════╝╚══════╝
// MY FAVORITES :: Display a listing of the resource that have been favorited by a specific user.
##################################################################################################################
	public function myFavorites()
	{

		if(!checkACL('user')) {
			return view('errors.backend.403');
		}
		// $alphas = DB::table('recipes')
		//   ->select(DB::raw('DISTINCT LEFT(title, 1) as letter'))
		//   //->where('user_id','=',Auth::user()->id)
		//   ->where('user_id','=',-1)
		//   ->orderBy('letter')
		//   ->get();
		// //dd($alphas);

		//$letters = [];
		//   foreach($alphas as $alpha) {
		//     $letters[] = $alpha->letter;
		//   }
		// //dd($letters);

		// find the favorites
		$favs = DB::table('article_user')->where('user_id','=',Auth::user()->id)->get();
		

		//dd($favs);
		//$favs = Recipe::with('user','category')->where('recipe_user.user_id','=',Auth::user()->id)->get();
		//$recipes = Recipe::with('user','category')->where('user_id','=', Auth::user()->id)->orderBy('title', 'asc')->get();

		// // Create an empty array to store the recipes        
		$articles = [];

		// // Store the recipe values into the $recipes array
		foreach ($favs as $fav)
		{
		  $articles[$fav->id] = Article::with('user','category')->find($fav->article_id);
		}
		//dd($articles);
		// // Sort the recipes array by title
		$articles = array_values(array_sort($articles, function ($value) {
			return $value['title'];
		}));
		//dd($articles);
		// return view('recipes.viewfavorites')->withRecipes($recipes);
		//return view('recipes.myFavorites', compact('recipes','letters'));
		//return view('recipes.index', compact('recipes','letters'));
		return view('backend.articles.myFavorites', compact('articles'));
	}


##################################################################################################################
# ███╗   ██╗███████╗██╗    ██╗     █████╗ ██████╗ ████████╗██╗ ██████╗██╗     ███████╗███████╗
# ████╗  ██║██╔════╝██║    ██║    ██╔══██╗██╔══██╗╚══██╔══╝██║██╔════╝██║     ██╔════╝██╔════╝
# ██╔██╗ ██║█████╗  ██║ █╗ ██║    ███████║██████╔╝   ██║   ██║██║     ██║     █████╗  ███████╗
# ██║╚██╗██║██╔══╝  ██║███╗██║    ██╔══██║██╔══██╗   ██║   ██║██║     ██║     ██╔══╝  ╚════██║
# ██║ ╚████║███████╗╚███╔███╔╝    ██║  ██║██║  ██║   ██║   ██║╚██████╗███████╗███████╗███████║
# ╚═╝  ╚═══╝╚══════╝ ╚══╝╚══╝     ╚═╝  ╚═╝╚═╝  ╚═╝   ╚═╝   ╚═╝ ╚═════╝╚══════╝╚══════╝╚══════╝
// Display a listing of the resource that were created since the user's last login.
##################################################################################################################
   public function newArticles(Request $request, $key=null)
   {
		if(!checkACL('user')) {
			return view('errors.backend.403');
		}

      //$alphas = range('A', 'Z');
      $alphas = DB::table('articles')
         ->select(DB::raw('DISTINCT LEFT(title, 1) as letter'))
         ->where('created_at', '>=' , Auth::user()->last_login_date)
         //->where('user_id', '=', Auth::user()->id)
         // ->where('personal', '!=', 1)
         // ->where('published_at','!=', null)
         ->orderBy('letter')
         ->get();
      //dd($alphas);

      $letters = [];
      foreach($alphas as $alpha) {
        $letters[] = $alpha->letter;
      }

      // If $key value is passed
      if ($key) {
         $articles = Article::with('user','category')->newArticles()
            ->where('title', 'like', $key . '%')
            ->get();
         return view('backend.articles.newArticles', compact('articles','letters'));
      }

      $articles = Article::with('user','category')->newarticles()->get();
      return view('backend.articles.newArticles', compact('articles','letters'));
   }


##################################################################################################################
# ██████╗ ██████╗ ███████╗    ██╗   ██╗██╗███████╗██╗    ██╗
# ██╔══██╗██╔══██╗██╔════╝    ██║   ██║██║██╔════╝██║    ██║
# ██████╔╝██║  ██║█████╗      ██║   ██║██║█████╗  ██║ █╗ ██║
# ██╔═══╝ ██║  ██║██╔══╝      ╚██╗ ██╔╝██║██╔══╝  ██║███╗██║
# ██║     ██████╔╝██║          ╚████╔╝ ██║███████╗╚███╔███╔╝
# ╚═╝     ╚═════╝ ╚═╝           ╚═══╝  ╚═╝╚══════╝ ╚══╝╚══╝ 
// 
##################################################################################################################
	// public function exportPDF()
	// {
	//   // if(!checkACL('manager')) {
	//   //   return view('errors.403');
	//   // }

	//   $data = Article::get()->toArray();
	//   return Excel::create('Articles_List', function($excel) use ($data) {
	//     $excel->sheet('mySheet', function($sheet) use ($data)
	//     {
	//       $sheet->fromArray($data);
	//     });
	//   })->download("pdf");
	// }

	// public function downloadPDF()
	// {
	//   $pdf = PDF::loadView('backend.articles.pdfView');
	//   return $pdf->download('articles.pdf');
	// }

	public function pdfview(Request $request)
	{
		if(!checkACL('manager')) {
			return view('errors.backend.403');
		}

		if(app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName() == 'backend.articles.newArticles') {
				$data = Article::newArticles()->get();
		}
		if(app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName() == 'backend.articles.published') {
				$data = Article::published()->get();
		}
		if(app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName() == 'backend.articles.myArticles') {
				$data = Article::myArticles()->get();
		}
		if(app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName() == 'backend.articles.unpublished') {
				$data = Article::unpublished()->get();
		}
		if(app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName() == 'backend.articles.future') {
				$data = Article::future()->get();
		}
		if(app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName() == 'backend.articles.trashed') {
				$data = Article::trashedCount()->get();
		}

		view()->share('articles',$data);

		if($request->has('download')){
			$pdf = PDF::loadView('backend.articles.pdfDownload');
			//$pdf->setPaper('A4', 'landscape');
			return $pdf->download('articles.pdf');
		}

		return view('backend.articles.pdfPreview');
	}


##################################################################################################################
# ██████╗ ██████╗ ██╗███╗   ██╗████████╗
# ██╔══██╗██╔══██╗██║████╗  ██║╚══██╔══╝
# ██████╔╝██████╔╝██║██╔██╗ ██║   ██║   
# ██╔═══╝ ██╔══██╗██║██║╚██╗██║   ██║   
# ██║     ██║  ██║██║██║ ╚████║   ██║   
# ╚═╝     ╚═╝  ╚═╝╚═╝╚═╝  ╚═══╝   ╚═╝   
##################################################################################################################
	public function printArticle($id)
	{
		// if(!checkACL('author')) {
		//     return view('errors.403');
		// }

		$article = Article::find($id);

		// Save entry to log file using built-in Monolog
		// Log::info(Auth::user()->username . " (" . Auth::user()->id . ") PRINTED article (" . $article->id . ")\r\n", 
		//     [json_decode($article, true)]
		// );

		return view('backend.articles.print')->withArticle($article);
	}


##################################################################################################################
# ██████╗ ██╗   ██╗██████╗ ██╗     ██╗███████╗██╗  ██╗
# ██╔══██╗██║   ██║██╔══██╗██║     ██║██╔════╝██║  ██║
# ██████╔╝██║   ██║██████╔╝██║     ██║███████╗███████║
# ██╔═══╝ ██║   ██║██╔══██╗██║     ██║╚════██║██╔══██║
# ██║     ╚██████╔╝██████╔╝███████╗██║███████║██║  ██║
# ╚═╝      ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚══════╝╚═╝  ╚═╝
##################################################################################################################
	public function publish($id)
	{
		// Pass along the ROUTE value of the previous page
		$ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

		$article = Article::withTrashed()->find($id);
		//dd($id);
			//dd($article);
		  //$article->published = 1;
		  $article->published_at = Carbon::now();
		  $article->deleted_at = Null;
		$article->save();

		Session::flash ('success','The article was successfully published');
		// return redirect()->route($ref);
		return redirect()->back();

	}


##################################################################################################################
# ██████╗ ██╗   ██╗██████╗ ██╗     ██╗███████╗██╗  ██╗     █████╗ ██╗     ██╗     
# ██╔══██╗██║   ██║██╔══██╗██║     ██║██╔════╝██║  ██║    ██╔══██╗██║     ██║     
# ██████╔╝██║   ██║██████╔╝██║     ██║███████╗███████║    ███████║██║     ██║     
# ██╔═══╝ ██║   ██║██╔══██╗██║     ██║╚════██║██╔══██║    ██╔══██║██║     ██║     
# ██║     ╚██████╔╝██████╔╝███████╗██║███████║██║  ██║    ██║  ██║███████╗███████╗
# ╚═╝      ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚══════╝╚═╝  ╚═╝    ╚═╝  ╚═╝╚══════╝╚══════╝
##################################################################################################################
	public function publishAll(Request $request)
	{
		// Pass along the ROUTE value of the previous page
		$ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

		$this->validate($request, [
			'checked' => 'required',
		]);

		$checked = $request->input('checked');

		foreach ($checked as $item) {
			$article = Article::withTrashed()->find($item);
				$article->published_at = Carbon::now();
				$article->deleted_at = Null;
			$article->save();
		}

		Session::flash('success','The articles were published successfully.');
		return redirect()->route($ref);
	}


##################################################################################################################
# ██████╗ ██╗   ██╗██████╗ ██╗     ██╗███████╗██╗  ██╗███████╗██████╗ 
# ██╔══██╗██║   ██║██╔══██╗██║     ██║██╔════╝██║  ██║██╔════╝██╔══██╗
# ██████╔╝██║   ██║██████╔╝██║     ██║███████╗███████║█████╗  ██║  ██║
# ██╔═══╝ ██║   ██║██╔══██╗██║     ██║╚════██║██╔══██║██╔══╝  ██║  ██║
# ██║     ╚██████╔╝██████╔╝███████╗██║███████║██║  ██║███████╗██████╔╝
# ╚═╝      ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚══════╝╚═╝  ╚═╝╚══════╝╚═════╝ 
##################################################################################################################
	public function published(Request $request, $key=null)
	{
		if(!checkACL('user')) {
			return view('errors.backend.403');
		}

		//$alphas = range('A', 'Z');
		  $alphas = DB::table('articles')
			->select(DB::raw('DISTINCT LEFT(title, 1) as letter'))
			->where('published_at','<', Carbon::Now())
			->where('deleted_at','=', Null)
			->orderBy('letter')
			->get();

		$letters = [];
		foreach($alphas as $alpha) {
		  $letters[] = $alpha->letter;
		}

		// If $key value is passed
		if ($key) {
			$articles = Article::with('user','category')->published()
				->where('title', 'like', $key . '%')
				->orderBy('title', 'asc')
				->get();
			return view('backend.articles.published', compact('articles','letters'));
		}

		// No $key value is passed
		$articles = Article::with('user','category')->published()->get();
		return view('backend.articles.published', compact('articles','letters'));
	}


##################################################################################################################
# ██████╗ ███████╗███╗   ███╗ ██████╗ ██╗   ██╗███████╗    ███████╗ █████╗ ██╗   ██╗ ██████╗ ██████╗ ██╗████████╗███████╗
# ██╔══██╗██╔════╝████╗ ████║██╔═══██╗██║   ██║██╔════╝    ██╔════╝██╔══██╗██║   ██║██╔═══██╗██╔══██╗██║╚══██╔══╝██╔════╝
# ██████╔╝█████╗  ██╔████╔██║██║   ██║██║   ██║█████╗      █████╗  ███████║██║   ██║██║   ██║██████╔╝██║   ██║   █████╗  
# ██╔══██╗██╔══╝  ██║╚██╔╝██║██║   ██║╚██╗ ██╔╝██╔══╝      ██╔══╝  ██╔══██║╚██╗ ██╔╝██║   ██║██╔══██╗██║   ██║   ██╔══╝  
# ██║  ██║███████╗██║ ╚═╝ ██║╚██████╔╝ ╚████╔╝ ███████╗    ██║     ██║  ██║ ╚████╔╝ ╚██████╔╝██║  ██║██║   ██║   ███████╗
# ╚═╝  ╚═╝╚══════╝╚═╝     ╚═╝ ╚═════╝   ╚═══╝  ╚══════╝    ╚═╝     ╚═╝  ╚═╝  ╚═══╝   ╚═════╝ ╚═╝  ╚═╝╚═╝   ╚═╝   ╚══════╝
##################################################################################################################
	public function removefavorite($id)
	{
		// Pass along the ROUTE value of the previous page
		$ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

		$user = Auth::user()->id;
		$article = Article::find($id);

		$article->favorites()->detach($user);

		Session::flash ('success','The article was successfully removed to your Favorites list!');
		// return redirect()->route('recipes.index','all');
		// return redirect()->route('backend.articles.myFavorites');
		//return redirect()->route($ref);
		return redirect()->back();

	}


##################################################################################################################
# ██████╗ ███████╗███╗   ███╗ ██████╗ ██╗   ██╗███████╗    ██████╗ ██████╗ ██╗██╗   ██╗ █████╗ ████████╗███████╗
# ██╔══██╗██╔════╝████╗ ████║██╔═══██╗██║   ██║██╔════╝    ██╔══██╗██╔══██╗██║██║   ██║██╔══██╗╚══██╔══╝██╔════╝
# ██████╔╝█████╗  ██╔████╔██║██║   ██║██║   ██║█████╗      ██████╔╝██████╔╝██║██║   ██║███████║   ██║   █████╗  
# ██╔══██╗██╔══╝  ██║╚██╔╝██║██║   ██║╚██╗ ██╔╝██╔══╝      ██╔═══╝ ██╔══██╗██║╚██╗ ██╔╝██╔══██║   ██║   ██╔══╝  
# ██║  ██║███████╗██║ ╚═╝ ██║╚██████╔╝ ╚████╔╝ ███████╗    ██║     ██║  ██║██║ ╚████╔╝ ██║  ██║   ██║   ███████╗
# ╚═╝  ╚═╝╚══════╝╚═╝     ╚═╝ ╚═════╝   ╚═══╝  ╚══════╝    ╚═╝     ╚═╝  ╚═╝╚═╝  ╚═══╝  ╚═╝  ╚═╝   ╚═╝   ╚══════╝
##################################################################################################################
	public function removeprivate($id)
	{
		// Pass along the ROUTE value of the previous page
		$ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

		$article = Article::find($id);
			$article->personal = 0;
		$article->save();

		// Save entry to log file using built-in Monolog
		//Log::info(Auth::user()->username . " (" . Auth::user()->id . ") REMOVE PRIVATE from recipe (" . $recipe->id . ")\r\n", 
		//    [json_decode($recipe, true)]
		//);

		Session::flash('success','The article was removed from private successfully');
		return redirect()->route($ref);
	}


##################################################################################################################
# ██████╗ ███████╗███████╗███████╗████████╗    ██╗   ██╗██╗███████╗██╗    ██╗███████╗
# ██╔══██╗██╔════╝██╔════╝██╔════╝╚══██╔══╝    ██║   ██║██║██╔════╝██║    ██║██╔════╝
# ██████╔╝█████╗  ███████╗█████╗     ██║       ██║   ██║██║█████╗  ██║ █╗ ██║███████╗
# ██╔══██╗██╔══╝  ╚════██║██╔══╝     ██║       ╚██╗ ██╔╝██║██╔══╝  ██║███╗██║╚════██║
# ██║  ██║███████╗███████║███████╗   ██║        ╚████╔╝ ██║███████╗╚███╔███╔╝███████║
# ╚═╝  ╚═╝╚══════╝╚══════╝╚══════╝   ╚═╝         ╚═══╝  ╚═╝╚══════╝ ╚══╝╚══╝ ╚══════╝
// RESET VIEWS COUNT
##################################################################################################################
	public function resetViews($id)
	{
		// Pass along the ROUTE value of the previous page
		$ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

		$article = Article::find($id);
			$article->views = 0;
		$article->save();

		// Save entry to log file using built-in Monolog
		//Log::info(Auth::user()->username . " (" . Auth::user()->id . ") MADE recipe (" . $recipe->id . ") PRIVATE \r\n", [json_decode($recipe, true)]);

		Session::flash('success','The article\'s views count was reset to 0.');
		// return redirect()->route($ref);
		return redirect()->back();
	}


##################################################################################################################
# ██████╗ ███████╗███████╗████████╗ ██████╗ ██████╗ ███████╗
# ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
# ██████╔╝█████╗  ███████╗   ██║   ██║   ██║██████╔╝█████╗  
# ██╔══██╗██╔══╝  ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝  
# ██║  ██║███████╗███████║   ██║   ╚██████╔╝██║  ██║███████╗
# ╚═╝  ╚═╝╚══════╝╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
// RESTORE TRASHED FILE
##################################################################################################################
	public function restore($id)
	{
		$article = Article::withTrashed()->findOrFail($id);

		//$article->deleted_at = NULL;
		//$article->save();
		$article->restore();

		Session::flash ('success','The article was successfully restored.');
		//return redirect()->route('backend.articles.trashed');
		return redirect()->back();
	}


##################################################################################################################
# ██████╗ ███████╗███████╗████████╗ ██████╗ ██████╗ ███████╗     █████╗ ██╗     ██╗     
# ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝    ██╔══██╗██║     ██║     
# ██████╔╝█████╗  ███████╗   ██║   ██║   ██║██████╔╝█████╗      ███████║██║     ██║     
# ██╔══██╗██╔══╝  ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝      ██╔══██║██║     ██║     
# ██║  ██║███████╗███████║   ██║   ╚██████╔╝██║  ██║███████╗    ██║  ██║███████╗███████╗
# ╚═╝  ╚═╝╚══════╝╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝    ╚═╝  ╚═╝╚══════╝╚══════╝
// RESTORE ALL TRASHED FILE
##################################################################################################################
	public function restoreAll(Request $request)
	{
		//dd('TEST_RESTORE');
		//dd($request);
		//$this->validate($request, [
		//    'checked' => 'required',
		//]);
		//dd('TEST_RESTORE');

		$checked = $request->input('checked');
		//dd($checked);

		// $article = new Article();
		// $article->restore($checked);
		Article::whereIn('id', $checked)->restore();

		Session::flash('success','The articles were restored successfully.');
		return redirect()->route('backend.articles.trashed');
	}


##################################################################################################################
# ███████╗██╗  ██╗ ██████╗ ██╗    ██╗
# ██╔════╝██║  ██║██╔═══██╗██║    ██║
# ███████╗███████║██║   ██║██║ █╗ ██║
# ╚════██║██╔══██║██║   ██║██║███╗██║
# ███████║██║  ██║╚██████╔╝╚███╔███╔╝
# ╚══════╝╚═╝  ╚═╝ ╚═════╝  ╚══╝╚══╝ 
// Display the specified resource
##################################################################################################################
	public function show($id)
	{
		// if(!checkACL('guest')) {
		//     return view('errors.403');
		// }

		$article = Article::withTrashed()->findOrFail($id);

		// Add 1 to views column
		//DB::table('articles')->where('id','=',$article->id)->increment('views',1);

		// Save entry to log file using built-in Monolog
		// if (Auth::check()) {
		//     Log::info(Auth::user()->username . " (" . Auth::user()->id . ") VIEWED article (" . $article->id . ")");
		// } else {
		//     Log::info('Guest viewed article (' . $article->id) . ')';
		// }

		return view('backend.articles.show', compact('article'));
	}


##################################################################################################################
# ███████╗████████╗ ██████╗ ██████╗ ███████╗
# ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
# ███████╗   ██║   ██║   ██║██████╔╝█████╗  
# ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝  
# ███████║   ██║   ╚██████╔╝██║  ██║███████╗
# ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
// Store a newly created resource in storage
##################################################################################################################
	public function store(CreateArticleRequest $request)
	{
		// if(!checkACL('author')) {
		//     return view('errors.403');
		// }

		$article = new Article;
			$article->title             = $request->title;
			$article->category_id       = $request->category_id;
			$article->published_at      = $request->published_at;
			$article->description_eng   = $request->description_eng;
			$article->description_fre   = $request->description_fre;
			$article->user_id           = Auth::user()->id;
		$article->save();

		// Save entry to log file using built-in Monolog
		//Log::info(Auth::user()->username . " (" . Auth::user()->id . ") CREATED article (" . $article->id . ")\r\n", [json_decode($article, true)]
		//);

		Session::flash('success','The article has been created successfully!');
		// return redirect()->route($request->ref);
		return redirect()->route('backend.articles.index');
	}


##################################################################################################################
# ████████╗██████╗  █████╗ ███████╗██╗  ██╗███████╗██████╗ 
# ╚══██╔══╝██╔══██╗██╔══██╗██╔════╝██║  ██║██╔════╝██╔══██╗
#    ██║   ██████╔╝███████║███████╗███████║█████╗  ██║  ██║
#    ██║   ██╔══██╗██╔══██║╚════██║██╔══██║██╔══╝  ██║  ██║
#    ██║   ██║  ██║██║  ██║███████║██║  ██║███████╗██████╔╝
#    ╚═╝   ╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝╚══════╝╚═════╝ 
// Display a list of resources that have been trashed (Soft Deleted)
##################################################################################################################
	public function trashed(Request $request)
	{
		if(!checkACL('manager')) {
			return view('errors.backend.403');
		}

		$articles = Article::with('user','category')->onlyTrashed()->get();
		return view('backend.articles.trashed', compact('articles'));
	}


##################################################################################################################
# ████████╗██████╗  █████╗ ███████╗██╗  ██╗     █████╗ ██╗     ██╗     
# ╚══██╔══╝██╔══██╗██╔══██╗██╔════╝██║  ██║    ██╔══██╗██║     ██║     
#    ██║   ██████╔╝███████║███████╗███████║    ███████║██║     ██║     
#    ██║   ██╔══██╗██╔══██║╚════██║██╔══██║    ██╔══██║██║     ██║     
#    ██║   ██║  ██║██║  ██║███████║██║  ██║    ██║  ██║███████╗███████╗
#    ╚═╝   ╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝    ╚═╝  ╚═╝╚══════╝╚══════╝
// Remove the specified resource from storage
// Used in the index page to soft delete multiple records
##################################################################################################################
	public function trashAll(Request $request)
	{
		// Pass along the ROUTE value of the previous page
		$ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

		$this->validate($request, [
			'checked' => 'required',
		]);

		$checked = $request->input('checked');
		//dd($checked);

		foreach($checked as $article) {
			$article = Article::findOrFail($article);
			$article->published_at = Null;
			$article->save();
			//dd($article);
		}

		Article::destroy($checked);

		Session::flash('success','The articles were trashed successfully.');
		return redirect()->route($ref);
	}


##################################################################################################################
# ██╗   ██╗███╗   ██╗██████╗ ██╗   ██╗██████╗ ██╗     ██╗███████╗██╗  ██╗
# ██║   ██║████╗  ██║██╔══██╗██║   ██║██╔══██╗██║     ██║██╔════╝██║  ██║
# ██║   ██║██╔██╗ ██║██████╔╝██║   ██║██████╔╝██║     ██║███████╗███████║
# ██║   ██║██║╚██╗██║██╔═══╝ ██║   ██║██╔══██╗██║     ██║╚════██║██╔══██║
# ╚██████╔╝██║ ╚████║██║     ╚██████╔╝██████╔╝███████╗██║███████║██║  ██║
#  ╚═════╝ ╚═╝  ╚═══╝╚═╝      ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚══════╝╚═╝  ╚═╝
##################################################################################################################
	public function unpublish($id)
	{
	// Pass along the ROUTE value of the previous page
	$ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

	$article = Article::find($id);
		$article->published_at = NULL;
		// $article->favoriteArticles()->delete(); // Remove associated rows from article_user (favorites table)
	  
		$favorites = DB::select('select * from article_user where article_id = '. $id, [1]);
		//dd ($favorites);
		foreach($favorites as $favorite) {
			//dd($favorite);
			$article->favorites()->detach($favorite);
		}

		$article->save();

		Session::flash ('success','The article was successfully unpublished');
		// return redirect()->route($ref);
		return redirect()->back();
	}


##################################################################################################################
# ██╗   ██╗███╗   ██╗██████╗ ██╗   ██╗██████╗ ██╗     ██╗███████╗██╗  ██╗     █████╗ ██╗     ██╗     
# ██║   ██║████╗  ██║██╔══██╗██║   ██║██╔══██╗██║     ██║██╔════╝██║  ██║    ██╔══██╗██║     ██║     
# ██║   ██║██╔██╗ ██║██████╔╝██║   ██║██████╔╝██║     ██║███████╗███████║    ███████║██║     ██║     
# ██║   ██║██║╚██╗██║██╔═══╝ ██║   ██║██╔══██╗██║     ██║╚════██║██╔══██║    ██╔══██║██║     ██║     
# ╚██████╔╝██║ ╚████║██║     ╚██████╔╝██████╔╝███████╗██║███████║██║  ██║    ██║  ██║███████╗███████╗
#  ╚═════╝ ╚═╝  ╚═══╝╚═╝      ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚══════╝╚═╝  ╚═╝    ╚═╝  ╚═╝╚══════╝╚══════╝
##################################################################################################################
	public function unpublishAll(Request $request)
	{
		// Pass along the ROUTE value of the previous page
		$ref = app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName();

		$this->validate($request, [
			'checked' => 'required',
		]);

		$checked = $request->input('checked');

		foreach ($checked as $item) {
			//dd($item);
			$article = Article::withTrashed()->find($item);
				$article->published_at = Null;

				// Delete related favorites
				$favorites = DB::select('select * from article_user where article_id = '. $article->id, [1]);
					foreach($favorites as $favorite) {
						$article->favorites()->detach($favorite);
					}
			$article->save();
		}
		

		Session::flash('success','The articles were published successfully.');
		return redirect()->route($ref);
	}


##################################################################################################################
# ██╗   ██╗███╗   ██╗██████╗ ██╗   ██╗██████╗ ██╗     ██╗███████╗██╗  ██╗███████╗██████╗ 
# ██║   ██║████╗  ██║██╔══██╗██║   ██║██╔══██╗██║     ██║██╔════╝██║  ██║██╔════╝██╔══██╗
# ██║   ██║██╔██╗ ██║██████╔╝██║   ██║██████╔╝██║     ██║███████╗███████║█████╗  ██║  ██║
# ██║   ██║██║╚██╗██║██╔═══╝ ██║   ██║██╔══██╗██║     ██║╚════██║██╔══██║██╔══╝  ██║  ██║
# ╚██████╔╝██║ ╚████║██║     ╚██████╔╝██████╔╝███████╗██║███████║██║  ██║███████╗██████╔╝
#  ╚═════╝ ╚═╝  ╚═══╝╚═╝      ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚══════╝╚═╝  ╚═╝╚══════╝╚═════╝ 
// Display a list of resources that have not been published
##################################################################################################################
	public function unpublished(Request $request, $key=null)
	{
		if(!checkACL('publisher')) {
			return view('errors.backend.403');
		}

		//$alphas = range('A', 'Z');
		  $alphas = DB::table('articles')
			->select(DB::raw('DISTINCT LEFT(title, 1) as letter'))
			// ->where('personal', '!=', 1)
			->where('published_at','=', null)
			->where('deleted_at','=', null)
			->orderBy('letter')
			->get();
			//dd($alphas);

		$letters = [];
		foreach($alphas as $alpha) {
			$letters[] = $alpha->letter;
		}

		// If $key value is passed
		if ($key) {
			$articles = Article::with('user','category')->unpublished()
				->where('title', 'like', $key . '%')
				->orderBy('title', 'asc')
				->get();
			return view('backend.articles.unpublished', compact('articles','letters'));
		}

		// No $key value is passed
		$articles = Article::with('user','category')->unpublished()->get();
		return view('backend.articles.unpublished', compact('articles','letters'));
	}


##################################################################################################################
# ██╗   ██╗██████╗ ██████╗  █████╗ ████████╗███████╗
# ██║   ██║██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██╔════╝
# ██║   ██║██████╔╝██║  ██║███████║   ██║   █████╗  
# ██║   ██║██╔═══╝ ██║  ██║██╔══██║   ██║   ██╔══╝  
# ╚██████╔╝██║     ██████╔╝██║  ██║   ██║   ███████╗
#  ╚═════╝ ╚═╝     ╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚══════╝
// UPDATE :: Update the specified resource in storage
##################################################################################################################
	public function update(UpdateArticleRequest $request, $id)
	{
		
		$article = Article::findOrFail($id);
			$article->title             = $request->title;
			$article->category_id       = $request->category_id;
			$article->published_at      = $request->published_at;
			$article->description_eng   = $request->description_eng;
			$article->description_fre   = $request->description_fre;
		$article->save();
		
		// Save entry to log file using built-in Monolog
		//Log::info(Auth::user()->username . " (" . Auth::user()->id . ") UPDATED article (" . $article->id . ")\r\n",
		//    [json_decode($article, true)]
		//);

		Session::flash('success','The article has been updated successfully.');
		return redirect()->route('backend.articles.show', $article);
	}


}
<file_sep><?php

use Illuminate\Database\Seeder;
use Faker\Factory as Faker;

class ClientsTableSeeder extends Seeder
{
	/**
	 * Run the database seeds.
	 *
	 * @return void
	 */
	public function run()
	{
		$faker = Faker::create();

		foreach (range(1,15) as $index) {
		
			DB::table('clients')->insert([
				'company_name' => $faker->company,
				'contact_name' => $faker->name,
				'address' => $faker->streetAddress,
				'city' => $faker->city,
				'state' => $faker->state,
				'zip' => $faker->postcode,
				'telephone' => $faker->phoneNumber,
				'cell' => $faker->phoneNumber,
				'fax' => $faker->phoneNumber,
				'email' => $faker->email,
				'website' => $faker->url,
				'notes' => $faker->paragraph
			]);
		}

	}
	
}
<file_sep><?php

namespace App\Http\Controllers\Frontend;

use Illuminate\Http\Request;
use App\Http\Requests\UpdateProfileRequest;
use App\Http\Controllers\Controller;

use Hash;
use Auth;
use Session;
use App\Category;
use App\Profile;
use App\User;
use Image;
use File;

class ProfileController extends Controller
{

##################################################################################################################
#  ██████╗ ██████╗ ███╗   ██╗███████╗████████╗██████╗ ██╗   ██╗ ██████╗████████╗
# ██╔════╝██╔═══██╗████╗  ██║██╔════╝╚══██╔══╝██╔══██╗██║   ██║██╔════╝╚══██╔══╝
# ██║     ██║   ██║██╔██╗ ██║███████╗   ██║   ██████╔╝██║   ██║██║        ██║   
# ██║     ██║   ██║██║╚██╗██║╚════██║   ██║   ██╔══██╗██║   ██║██║        ██║   
# ╚██████╗╚██████╔╝██║ ╚████║███████║   ██║   ██║  ██║╚██████╔╝╚██████╗   ██║   
#  ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝  ╚═════╝   ╚═╝   
##################################################################################################################
	 public function __construct()
	 {
			$this->middleware('auth');
	 }


##################################################################################################################
#  ██████╗██╗  ██╗ █████╗ ███╗   ██╗ ██████╗ ███████╗    ██████╗ ██╗    ██╗██████╗ 
# ██╔════╝██║  ██║██╔══██╗████╗  ██║██╔════╝ ██╔════╝    ██╔══██╗██║    ██║██╔══██╗
# ██║     ███████║███████║██╔██╗ ██║██║  ███╗█████╗      ██████╔╝██║ █╗ ██║██║  ██║
# ██║     ██╔══██║██╔══██║██║╚██╗██║██║   ██║██╔══╝      ██╔═══╝ ██║███╗██║██║  ██║
# ╚██████╗██║  ██║██║  ██║██║ ╚████║╚██████╔╝███████╗    ██║     ╚███╔███╔╝██████╔╝
#  ╚═════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝ ╚═════╝ ╚══════╝    ╚═╝      ╚══╝╚══╝ ╚═════╝ 
##################################################################################################################
	public function changePassword(Request $request){

		if (!(Hash::check($request->get('current-password'), Auth::user()->password))) {
			// The current password does not match the one provided
			return redirect()->back()->with("error","Your current password does not match the password you provided. Please try again.")->withInput(['tab'=>'changePwd']);
		}

		if(strcmp($request->get('current-password'), $request->get('new-password')) == 0){
			// Current password and new password are the same
			return redirect()->back()->with("error","The new password cannot be the same as your current password. Please choose a different password.")->withInput(['tab'=>'changePwd']);
		}

		$validatedData = $request->validate([
			'current-password' => '<PASSWORD>',
			'new-password' => 'required|string|min:6|confirmed',
		]);

		//Change Password
		$user = Auth::user();
			 $user->password = <PASSWORD>($request->get('new-password'));
		$user->save();
		
		return redirect()->back()->with("success","Password changed successfully!")->withInput(['tab'=>'changePwd']);
	}


##################################################################################################################
# ██████╗ ███████╗██╗     ███████╗████████╗███████╗    ██╗███╗   ███╗ █████╗  ██████╗ ███████╗
# ██╔══██╗██╔════╝██║     ██╔════╝╚══██╔══╝██╔════╝    ██║████╗ ████║██╔══██╗██╔════╝ ██╔════╝
# ██║  ██║█████╗  ██║     █████╗     ██║   █████╗      ██║██╔████╔██║███████║██║  ███╗█████╗  
# ██║  ██║██╔══╝  ██║     ██╔══╝     ██║   ██╔══╝      ██║██║╚██╔╝██║██╔══██║██║   ██║██╔══╝  
# ██████╔╝███████╗███████╗███████╗   ██║   ███████╗    ██║██║ ╚═╝ ██║██║  ██║╚██████╔╝███████╗
# ╚═════╝ ╚══════╝╚══════╝╚══════╝   ╚═╝   ╚══════╝    ╚═╝╚═╝     ╚═╝╚═╝  ╚═╝ ╚═════╝ ╚══════╝
##################################################################################################################
	public function deleteImage($id)
	{
		// Find the user
		$profile = Profile::find($id);

		// Delete the image from the system
		File::delete('_profiles/' . $profile->image);
		
		// Update database
		$profile->image = NULL;
		$profile->save();

		// Set flash data with success message and return user to same tab
		Session::flash ('success', 'Your profile image was successfully removed!');
		return redirect()->route('profile', $id)->withInput(['tab'=>'profile']);
	}


##################################################################################################################
# ██╗███╗   ██╗██████╗ ███████╗██╗  ██╗
# ██║████╗  ██║██╔══██╗██╔════╝╚██╗██╔╝
# ██║██╔██╗ ██║██║  ██║█████╗   ╚███╔╝ 
# ██║██║╚██╗██║██║  ██║██╔══╝   ██╔██╗ 
# ██║██║ ╚████║██████╔╝███████╗██╔╝ ██╗
# ╚═╝╚═╝  ╚═══╝╚═════╝ ╚══════╝╚═╝  ╚═╝
// Display a list of resources
##################################################################################################################
	 public function index($id)
	 {
		// Find the logged in user
		$user = User::with('profile')->findOrFail(Auth::user()->id);
		//dd($user);

		// find all projects categories in the categories table and pass them to the view
		if(checkACL('manager')) {
			$landingpages = Category::whereHas('module', function ($query) {
				$query
					->where('name', '=', 'landing pages');
			})->orderBy('name','asc')->get();
		} else {
			$landingpages = Category::whereHas('module', function ($query) {
				$query
					->where('name', '=', 'landing pages')
					//->where('value', 'NOT LIKE', '%(BE)%')
				;
			})->orderBy('name','asc')->get();
		}

		// Create an empty array to store the categories
		$landingPages = [];

		// Store the category values into the $cats array
		foreach ($landingpages as $landingPage) {
			$landingPages[$landingPage->id] = ucfirst($landingPage->value);
		}

		return view('frontend.profiles.index', compact('user'))->withLandingPages($landingPages);
	}


##################################################################################################################
# ██████╗ ███████╗███████╗███████╗████████╗    ███████╗███████╗████████╗████████╗██╗███╗   ██╗ ██████╗ ███████╗
# ██╔══██╗██╔════╝██╔════╝██╔════╝╚══██╔══╝    ██╔════╝██╔════╝╚══██╔══╝╚══██╔══╝██║████╗  ██║██╔════╝ ██╔════╝
# ██████╔╝█████╗  ███████╗█████╗     ██║       ███████╗█████╗     ██║      ██║   ██║██╔██╗ ██║██║  ███╗███████╗
# ██╔══██╗██╔══╝  ╚════██║██╔══╝     ██║       ╚════██║██╔══╝     ██║      ██║   ██║██║╚██╗██║██║   ██║╚════██║
# ██║  ██║███████╗███████║███████╗   ██║       ███████║███████╗   ██║      ██║   ██║██║ ╚████║╚██████╔╝███████║
# ╚═╝  ╚═╝╚══════╝╚══════╝╚══════╝   ╚═╝       ╚══════╝╚══════╝   ╚═╝      ╚═╝   ╚═╝╚═╝  ╚═══╝ ╚═════╝ ╚══════╝
##################################################################################################################
	// public function resetSettings(Request $request, $id)
	// {
	// 	$profile = Profile::findOrFail($id);
	// 		 $profile->frontendStyle = 'slate';
	// 		 $profile->backendStyle = 'bootstrap';
	// 		 $profile->author_format = 1;
	// 		 $profile->alert_fade_time = 5000;
	// 		 $profile->date_format = 1;
	// 		 $profile->landing_page = 'home';
	// 		 $profile->rows_per_page = 15;
	// 		 $profile->display_size = 'normal';
	// 		 $profile->action_buttons = 1;
	// 		 $profile->layout = 1;
	// 	$profile->save();
		
	// 	// Save entry to log file using built-in Monolog
	// 	//Log::info(Auth::user()->username . " (" . Auth::user()->id . ") UPDATED article (" . $article->id . ")\r\n",
	// 	//    [json_decode($article, true)]
	// 	//);

	// 	Session::flash('success','Your preferences have been reset to their default values successfully.');
	// 	return redirect()->route('frontend.profile', $id)->withInput(['tab'=>'settings']);
	//  }


##################################################################################################################
# ███████╗██╗  ██╗ ██████╗ ██╗    ██╗
# ██╔════╝██║  ██║██╔═══██╗██║    ██║
# ███████╗███████║██║   ██║██║ █╗ ██║
# ╚════██║██╔══██║██║   ██║██║███╗██║
# ███████║██║  ██║╚██████╔╝╚███╔███╔╝
# ╚══════╝╚═╝  ╚═╝ ╚═════╝  ╚══╝╚══╝ 
// Display the specified resource
##################################################################################################################
	 public function show($id)
	 {
			$user = User::findOrFail($id);
			//dd($user);
			return view('frontend.profiles.index', compact('user'));
	 }


##################################################################################################################
# ██╗   ██╗██████╗ ██████╗  █████╗ ████████╗███████╗
# ██║   ██║██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██╔════╝
# ██║   ██║██████╔╝██║  ██║███████║   ██║   █████╗  
# ██║   ██║██╔═══╝ ██║  ██║██╔══██║   ██║   ██╔══╝  
# ╚██████╔╝██║     ██████╔╝██║  ██║   ██║   ███████╗
#  ╚═════╝ ╚═╝     ╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚══════╝
// UPDATE :: Update the specified resource in storage
##################################################################################################################
	 public function update(UpdateProfileRequest $request, $id)
	 {

		$profile = Profile::findOrFail($id);

			$profile->first_name = $request->first_name;
			$profile->last_name = $request->last_name;
			$profile->telephone = $request->telephone;
			//$profile->image = $request->image;

			// Check if a new image was submitted
			if ($request->hasFile('image')) {
				//Add new photo
				$image = $request->file('image');
				$filename = time() . '.' . $image->getClientOriginalExtension();
				//dd($filename);
				$location = public_path('_profiles/' . $filename);
				Image::make($image)->resize(800, 400)->save($location);
					
				// get name of old image
				$oldImageName = $profile->image;
					
				// Update database
				$profile->image = $filename;

				// Delete old photo
				//Storage::delete($oldImageName);
				File::delete('_profiles/' . $oldImageName);
			 }

		$profile->save();
		
		// Save entry to log file using built-in Monolog
		//Log::info(Auth::user()->username . " (" . Auth::user()->id . ") UPDATED article (" . $article->id . ")\r\n",
		//    [json_decode($article, true)]
		//);

		Session::flash('success','Your profile has been updated successfully.');
		return redirect()->route('profile', $profile->id)->withInput(['tab'=>'profile']);
	 }


##################################################################################################################
# ██╗   ██╗██████╗ ██████╗  █████╗ ████████╗███████╗     █████╗  ██████╗ ██████╗████████╗
# ██║   ██║██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██╔════╝    ██╔══██╗██╔════╝██╔════╝╚══██╔══╝
# ██║   ██║██████╔╝██║  ██║███████║   ██║   █████╗      ███████║██║     ██║        ██║   
# ██║   ██║██╔═══╝ ██║  ██║██╔══██║   ██║   ██╔══╝      ██╔══██║██║     ██║        ██║   
# ╚██████╔╝██║     ██████╔╝██║  ██║   ██║   ███████╗    ██║  ██║╚██████╗╚██████╗   ██║   
#  ╚═════╝ ╚═╝     ╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚══════╝    ╚═╝  ╚═╝ ╚═════╝ ╚═════╝   ╚═╝   
##################################################################################################################
	public function updateAcct(Request $request, $id)
	{

		$user = User::findOrFail($id);
		//dd($user);
			 $user->email = $request->email;
			 $user->public_email = $request->public_email;
		$user->save();
		
		// Save entry to log file using built-in Monolog
		//Log::info(Auth::user()->username . " (" . Auth::user()->id . ") UPDATED article (" . $article->id . ")\r\n",
		//    [json_decode($article, true)]
		//);

		Session::flash('success','Your account has been updated successfully.');
		return redirect()->route('profile', $id)->withInput(['tab'=>'account']);
	 }

##################################################################################################################
# ██╗   ██╗██████╗ ██████╗  █████╗ ████████╗███████╗    ███████╗███████╗████████╗████████╗██╗███╗   ██╗ ██████╗ ███████╗
# ██║   ██║██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██╔════╝    ██╔════╝██╔════╝╚══██╔══╝╚══██╔══╝██║████╗  ██║██╔════╝ ██╔════╝
# ██║   ██║██████╔╝██║  ██║███████║   ██║   █████╗      ███████╗█████╗     ██║      ██║   ██║██╔██╗ ██║██║  ███╗███████╗
# ██║   ██║██╔═══╝ ██║  ██║██╔══██║   ██║   ██╔══╝      ╚════██║██╔══╝     ██║      ██║   ██║██║╚██╗██║██║   ██║╚════██║
# ╚██████╔╝██║     ██████╔╝██║  ██║   ██║   ███████╗    ███████║███████╗   ██║      ██║   ██║██║ ╚████║╚██████╔╝███████║
#  ╚═════╝ ╚═╝     ╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚══════╝    ╚══════╝╚══════╝   ╚═╝      ╚═╝   ╚═╝╚═╝  ╚═══╝ ╚═════╝ ╚══════╝
##################################################################################################################
	public function updateSettings(Request $request, $id)
	{
		$profile = Profile::findOrFail($id);
			 $profile->frontendStyle = $request->frontendStyle;
			 $profile->backendStyle = $request->backendStyle;
			 $profile->author_format = $request->author_format;
			 $profile->alert_fade_time = $request->alert_fade_time;
			 $profile->date_format = $request->date_format;
			 $profile->landing_page_id = $request->landing_page_id;
			 $profile->rows_per_page = $request->rows_per_page;
			 $profile->display_size = $request->display_size;
			 $profile->action_buttons = $request->action_buttons;
			 $profile->layout = $request->layout;
		$profile->save();
		
		// Save entry to log file using built-in Monolog
		//Log::info(Auth::user()->username . " (" . Auth::user()->id . ") UPDATED article (" . $article->id . ")\r\n",
		//    [json_decode($article, true)]
		//);

		Session::flash('success','Your preferences have been updated successfully.');
		return redirect()->route('profile', $id)->withInput(['tab'=>'settings']);
	 }


	public function pwdChange($id)
	{
		return redirect()->route('profile', $id)->withInput(['tab'=>'changePwd']);
	}


	public function settingsUpdate($id)
	{
		return redirect()->route('profile', $id)->withInput(['tab'=>'settings']);
	}

	public function acctUpdate($id)
	{
		return redirect()->route('profile', $id)->withInput(['tab'=>'account']);
	}

}
<file_sep><?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateProfilesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // Profiles table will store info/settings that users can modify themselves
        Schema::create('profiles', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned();
            $table->string('first_name')->nullable();
            $table->string('last_name')->nullable();
            $table->string('telephone')->nullable();
            $table->string('image')->nullable();
            $table->string('frontendStyle')->default('slate');
            $table->string('backendStyle')->default('bootstrap');
            $table->integer('date_format')->default(1);
            $table->string('landing_page_id')->default(41);
            $table->unsignedinteger('rows_per_page')->default(15);
            $table->string('display_size')->default('normal');
            $table->string('action_buttons')->default(1);
            $table->string('author_format')->default(1);
            $table->unsignedinteger('alert_fade_time')->default(5000);
            $table->unsignedinteger('layout')->default(1);
            $table->softDeletes();

            // address
            // country
            // dob
            //etc

            // With the cascading delete option in place, deleting a user from the database will automatically result in the deletion of the user's corresponding profile.
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('profiles');
    }
}
<file_sep><?php

return [
	
	// GENERAL SITE SETTINGS

	// How many rows to display in the tables
	'rowsPerPage' => 10,
	
];<file_sep><?php

namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Module;
use Auth;
use DB;
use Excel;
use File;
use Image;
use Purifier;
use Session;
use Storage;
use Log;

use App\Http\Requests\CreateModuleRequest;
use App\Http\Requests\UpdatemoduleRequest;

class ModulesController extends Controller
{

##################################################################################################################
#  ██████╗ ██████╗ ███╗   ██╗███████╗████████╗██████╗ ██╗   ██╗ ██████╗████████╗
# ██╔════╝██╔═══██╗████╗  ██║██╔════╝╚══██╔══╝██╔══██╗██║   ██║██╔════╝╚══██╔══╝
# ██║     ██║   ██║██╔██╗ ██║███████╗   ██║   ██████╔╝██║   ██║██║        ██║   
# ██║     ██║   ██║██║╚██╗██║╚════██║   ██║   ██╔══██╗██║   ██║██║        ██║   
# ╚██████╗╚██████╔╝██║ ╚████║███████║   ██║   ██║  ██║╚██████╔╝╚██████╗   ██║   
#  ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝  ╚═════╝   ╚═╝   
##################################################################################################################
  public function __construct() {
    // only allow authenticated users to access these pages
    $this->middleware('auth');

    //Log::useFiles(storage_path().'/logs/Admin_Modules.log');
  }


##################################################################################################################
# ██╗███╗   ██╗██████╗ ███████╗██╗  ██╗
# ██║████╗  ██║██╔══██╗██╔════╝╚██╗██╔╝
# ██║██╔██╗ ██║██║  ██║█████╗   ╚███╔╝ 
# ██║██║╚██╗██║██║  ██║██╔══╝   ██╔██╗ 
# ██║██║ ╚████║██████╔╝███████╗██╔╝ ██╗
# ╚═╝╚═╝  ╚═══╝╚═════╝ ╚══════╝╚═╝  ╚═╝
// Display a list of resources
##################################################################################################################
	public function index()
  {
    // if(!checkACL('manager')) {
    //   return view('errors.403');
    // }

    $modules = Module::orderBy('name','ASC')->get();
    return view('backend.modules.index',compact('modules'));
}


##################################################################################################################
# ███████╗████████╗ ██████╗ ██████╗ ███████╗
# ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
# ███████╗   ██║   ██║   ██║██████╔╝█████╗  
# ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝  
# ███████║   ██║   ╚██████╔╝██║  ██║███████╗
# ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
// Store a newly created resource in storage
##################################################################################################################
  public function store(CreateModuleRequest $request)
  {
    // if(!checkACL('manager')) {
    //   return view('errors.403');
    // }

    $module = new Module;
      $module->name = $request->name;
    $module->save();

    // Save entry to log file using built-in Monolog
    //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") CREATED module (" . $module->id . ")\r\n", [json_decode($module, true)]);

    Session::flash('success','The new module has been created.');
    return redirect()->route('backend.modules.index');
  }


##################################################################################################################
# ███████╗██████╗ ██╗████████╗
# ██╔════╝██╔══██╗██║╚══██╔══╝
# █████╗  ██║  ██║██║   ██║   
# ██╔══╝  ██║  ██║██║   ██║   
# ███████╗██████╔╝██║   ██║   
# ╚══════╝╚═════╝ ╚═╝   ╚═╝   
// Show the form for editing the specified resource
##################################################################################################################
  public function edit($id)
  {
    // if(!checkACL('manager')) {
    //   return view('errors.403');
    // }

    $module = Module::find($id);
    return  view('backend.modules.edit', compact('module'));
  }


##################################################################################################################
# ██╗   ██╗██████╗ ██████╗  █████╗ ████████╗███████╗
# ██║   ██║██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██╔════╝
# ██║   ██║██████╔╝██║  ██║███████║   ██║   █████╗  
# ██║   ██║██╔═══╝ ██║  ██║██╔══██║   ██║   ██╔══╝  
# ╚██████╔╝██║     ██████╔╝██║  ██║   ██║   ███████╗
#  ╚═════╝ ╚═╝     ╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚══════╝
// UPDATE :: Update the specified resource in storage
##################################################################################################################
  public function update(UpdateModuleRequest $request, $id)
  {
    // if(!checkACL('manager')) {
    //   return view('errors.403');
    // }

    // Get the category value from the database
    $module = Module::find($id);
      $module->name = $request->input('name');
    $module->save();

    // Save entry to log file using built-in Monolog
    //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") UPDATED module (" . $module->id . ")\r\n", [json_decode($module, true)]);

    // Set flash data with success message
    Session::flash ('success', 'The module was successfully updated!');
    // Redirect to posts.show
    return redirect()->route('backend.modules.index');
  }


##################################################################################################################
# ██████╗ ███████╗███████╗████████╗██████╗  ██████╗ ██╗   ██╗
# ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔══██╗██╔═══██╗╚██╗ ██╔╝
# ██║  ██║█████╗  ███████╗   ██║   ██████╔╝██║   ██║ ╚████╔╝ 
# ██║  ██║██╔══╝  ╚════██║   ██║   ██╔══██╗██║   ██║  ╚██╔╝  
# ██████╔╝███████╗███████║   ██║   ██║  ██║╚██████╔╝   ██║   
# ╚═════╝ ╚══════╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝    ╚═╝   
// Remove the specified resource from storage
// Used in the index page and trashAll action to soft delete multiple records
##################################################################################################################
  public function destroy($id)
  {
    // if(!checkACL('manager')) {
    //   return view('errors.403');
    // }

    $module = Module::find($id);

    // $categories = Category::where('module_id', '=', $id);
    // dd($categories);

    $module->delete();

    // Save entry to log file using built-in Monolog
    //Log::info(Auth::user()->username . " (" . Auth::user()->id . ") DELETED module (" . $module->id . ")\r\n", [json_decode($module, true)]);

    Session::flash('success', 'The module was successfully deleted!');
    return redirect()->route('backend.modules.index');
  }


##################################################################################################################
# ███████╗██╗  ██╗██████╗  ██████╗ ██████╗ ████████╗    ██████╗ ██████╗ ███████╗
# ██╔════╝╚██╗██╔╝██╔══██╗██╔═══██╗██╔══██╗╚══██╔══╝    ██╔══██╗██╔══██╗██╔════╝
# █████╗   ╚███╔╝ ██████╔╝██║   ██║██████╔╝   ██║       ██████╔╝██║  ██║█████╗  
# ██╔══╝   ██╔██╗ ██╔═══╝ ██║   ██║██╔══██╗   ██║       ██╔═══╝ ██║  ██║██╔══╝  
# ███████╗██╔╝ ██╗██║     ╚██████╔╝██║  ██║   ██║       ██║     ██████╔╝██║     
# ╚══════╝╚═╝  ╚═╝╚═╝      ╚═════╝ ╚═╝  ╚═╝   ╚═╝       ╚═╝     ╚═════╝ ╚═╝     
##################################################################################################################
	public function exportPDF()
  {
    if(!checkACL('manager')) {
      return view('errors.403');
    }

    $data = Module::get()->toArray();
    return Excel::create('Modules_List', function($excel) use ($data) {
      $excel->sheet('mySheet', function($sheet) use ($data)
      {
        $sheet->fromArray($data);
      });
    })->download("pdf");
  }


##################################################################################################################
# ██╗███╗   ███╗██████╗  ██████╗ ██████╗ ████████╗
# ██║████╗ ████║██╔══██╗██╔═══██╗██╔══██╗╚══██╔══╝
# ██║██╔████╔██║██████╔╝██║   ██║██████╔╝   ██║   
# ██║██║╚██╔╝██║██╔═══╝ ██║   ██║██╔══██╗   ██║   
# ██║██║ ╚═╝ ██║██║     ╚██████╔╝██║  ██║   ██║   
# ╚═╝╚═╝     ╚═╝╚═╝      ╚═════╝ ╚═╝  ╚═╝   ╚═╝   
// IMPORT :: Show the form for importing entries to storage.
##################################################################################################################
  public function import()
  {
    if(!checkACL('manager')) {
      return view('errors.403');
    }

    return view('backend.modules.import');
  }


##################################################################################################################
# ██████╗  ██████╗ ██╗    ██╗███╗   ██╗██╗      ██████╗  █████╗ ██████╗     ███████╗██╗  ██╗ ██████╗███████╗██╗     
# ██╔══██╗██╔═══██╗██║    ██║████╗  ██║██║     ██╔═══██╗██╔══██╗██╔══██╗    ██╔════╝╚██╗██╔╝██╔════╝██╔════╝██║     
# ██║  ██║██║   ██║██║ █╗ ██║██╔██╗ ██║██║     ██║   ██║███████║██║  ██║    █████╗   ╚███╔╝ ██║     █████╗  ██║     
# ██║  ██║██║   ██║██║███╗██║██║╚██╗██║██║     ██║   ██║██╔══██║██║  ██║    ██╔══╝   ██╔██╗ ██║     ██╔══╝  ██║     
# ██████╔╝╚██████╔╝╚███╔███╔╝██║ ╚████║███████╗╚██████╔╝██║  ██║██████╔╝    ███████╗██╔╝ ██╗╚██████╗███████╗███████╗
# ╚═════╝  ╚═════╝  ╚══╝╚══╝ ╚═╝  ╚═══╝╚══════╝ ╚═════╝ ╚═╝  ╚═╝╚═════╝     ╚══════╝╚═╝  ╚═╝ ╚═════╝╚══════╝╚══════╝
##################################################################################################################
  public function downloadExcel($type)
  {
    if(!checkACL('manager')) {
      return view('errors.403');
    }

    $data = Module::get()->toArray();
    return Excel::create('Modules_List', function($excel) use ($data) {
      $excel->sheet('mySheet', function($sheet) use ($data)
      {
        $sheet->fromArray($data);
      });
    })->download($type);
  }


##################################################################################################################
# ██╗███╗   ███╗██████╗  ██████╗ ██████╗ ████████╗    ███████╗██╗   ██╗███╗   ██╗ ██████╗████████╗██╗ ██████╗ ███╗   ██╗
# ██║████╗ ████║██╔══██╗██╔═══██╗██╔══██╗╚══██╔══╝    ██╔════╝██║   ██║████╗  ██║██╔════╝╚══██╔══╝██║██╔═══██╗████╗  ██║
# ██║██╔████╔██║██████╔╝██║   ██║██████╔╝   ██║       █████╗  ██║   ██║██╔██╗ ██║██║        ██║   ██║██║   ██║██╔██╗ ██║
# ██║██║╚██╔╝██║██╔═══╝ ██║   ██║██╔══██╗   ██║       ██╔══╝  ██║   ██║██║╚██╗██║██║        ██║   ██║██║   ██║██║╚██╗██║
# ██║██║ ╚═╝ ██║██║     ╚██████╔╝██║  ██║   ██║       ██║     ╚██████╔╝██║ ╚████║╚██████╗   ██║   ██║╚██████╔╝██║ ╚████║
# ╚═╝╚═╝     ╚═╝╚═╝      ╚═════╝ ╚═╝  ╚═╝   ╚═╝       ╚═╝      ╚═════╝ ╚═╝  ╚═══╝ ╚═════╝   ╚═╝   ╚═╝ ╚═════╝ ╚═╝  ╚═══╝
##################################################################################################################
  public function importExcel()
  {
    if(!checkACL('manager')) {
      return view('errors.403');
    }

    if(Input::hasFile('import_file')){
      $path = Input::file('import_file')->getRealPath();
      $data = Excel::load($path, function($reader) {})->get();
      
      if(!empty($data) && $data->count()){
        foreach ($data as $key => $value) {
          $insert[] = [
            'name'         => $value->name,
            'created_at'    => $value->created_at,
            'updated_at'    => $value->updated_at,
          ];
        }
              
        if(!empty($insert)){
          DB::table('modules')->insert($insert);
          //dd('Insert Record successfully.');
          Session::flash('Success','Import was successfull!');
          //return view('roles.index');
          return redirect()->route('backend.modules.index');
        }
      }
    }
    return back();
  }


##################################################################################################################
# ███╗   ██╗███████╗██╗    ██╗    ███╗   ███╗ ██████╗ ██████╗ ██╗   ██╗██╗     ███████╗███████╗
# ████╗  ██║██╔════╝██║    ██║    ████╗ ████║██╔═══██╗██╔══██╗██║   ██║██║     ██╔════╝██╔════╝
# ██╔██╗ ██║█████╗  ██║ █╗ ██║    ██╔████╔██║██║   ██║██║  ██║██║   ██║██║     █████╗  ███████╗
# ██║╚██╗██║██╔══╝  ██║███╗██║    ██║╚██╔╝██║██║   ██║██║  ██║██║   ██║██║     ██╔══╝  ╚════██║
# ██║ ╚████║███████╗╚███╔███╔╝    ██║ ╚═╝ ██║╚██████╔╝██████╔╝╚██████╔╝███████╗███████╗███████║
# ╚═╝  ╚═══╝╚══════╝ ╚══╝╚══╝     ╚═╝     ╚═╝ ╚═════╝ ╚═════╝  ╚═════╝ ╚══════╝╚══════╝╚══════╝
// Display a listing of the resource that were created since the user's last login.
##################################################################################################################
   public function newModules(Request $request, $key=null)
   {
      // if(!checkACL('guest')) {
      //     return view('errors.403');
      // }

      //$alphas = range('A', 'Z');
      $alphas = DB::table('modules')
         ->select(DB::raw('DISTINCT LEFT(name, 1) as letter'))
         ->where('created_at', '>=' , Auth::user()->last_login_date)
         //->where('user_id', '=', Auth::user()->id)
         // ->where('personal', '!=', 1)
         // ->where('published_at','!=', null)
         ->orderBy('letter')
         ->get();
      //dd($alphas);

      $letters = [];
      foreach($alphas as $alpha) {
        $letters[] = $alpha->letter;
      }

      // If $key value is passed
      if ($key) {
         $modules = Module::newModules()
            ->where('namee', 'like', $key . '%')
            ->get();
         return view('backend.modules.newModules', compact('modules','letters'));
      }

      $modules = Module::newModules()->get();
      return view('backend.modules.newModules', compact('modules','letters'));
   }

   
 }<file_sep><?php
/*
|--------------------------------------------------------------------------
| COMMENTS ROUTES
|--------------------------------------------------------------------------
*/
// Route::post('comments/{post_id}', [
// 	'uses' => 'Frontend\CommentsController@store',
// 	'as' => 'comments.store',
// ]);

/*
|--------------------------------------------------------------------------
| COMMENTS ADMIN ROUTES
|--------------------------------------------------------------------------
*/
//Route::get('backend/comments/{id}',        ['uses' => 'Backend\CommentsController@show',            'as' => 'backend.comments.show']);
Route::get('backend/comment/{id}',        ['uses' => 'Backend\CommentsController@show',            'as' => 'backend.comments.show']);

Route::group(['prefix'=>'backend/comments'], function()
{
	$c = 'Backend\CommentsController@';
	$r = 'backend.comments.';

	//Route::get('{id}/delete',					['uses' => $c . 'delete',						'as' => $r . 'delete']);
	//Route::get('exportPDF',						['uses' => $c . 'exportPDF',					'as' => $r . 'exportPDF']);
	//Route::get('import',							['uses' => $c . 'import',						'as' => $r . 'import']);
	//Route::get('downloadExcel/{type}',		['uses' => $c . 'downloadExcel',				'as' => $r . 'downloadExcel']);
	//Route::post('importExcel',					['uses' => $c . 'importExcel',				'as' => $r . 'importExport']);
	Route::get('newComments',       			   ['uses' => $c . 'newComments', 			   'as' => $r . 'newComments']);

	Route::get('create',							['uses' => $c . 'create',						'as' => $r . 'create']);
	Route::post('store',							['uses' => $c . 'store',						'as' => $r . 'store']);
	Route::get('',									['uses' => $c . 'index',						'as' => $r . 'index']);
	Route::get('{id}/edit',						['uses' => $c . 'edit',							'as' => $r . 'edit']);
	Route::put('{id}',							['uses' => $c . 'update',						'as' => $r . 'update']);
	Route::delete('{id}',						['uses' => $c . 'destroy',						'as' => $r . 'destroy']);

	Route::get('{id}/print',					['uses' => $c . 'print',						'as' => $r . 'print']);

});<file_sep><?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Auth;
use Carbon\Carbon;

class WoodProject extends Model
{
   
   protected $table = 'woodprojects';
   protected $dates = ['deleted_at', 'completed_at'];
   protected $fillable = ['name', 'description', 'main_image'];

   public function comments()
   {
      return $this->morphMany('\App\Comment', 'commentable')->orderBy('id','desc');
   }
   
   // A project has many images
   public function projectImages() {
      return $this->hasMany('App\WoodProjectImage');
   }

   public function category() { 
      return $this->belongsTo(Category::class);
   }

   public function woodSpecie () {
      return $this->belongsTo(Category::class);
   }

   public function woodType () {
      return $this->belongsTo(Category::class);
   }

   public function stainType () {
      return $this->belongsTo(Category::class);
   }

   public function stainColor () {
      return $this->belongsTo(Category::class);
   }

   public function stainSheen () {
      return $this->belongsTo(Category::class);
   }

   public function finishType () {
      return $this->belongsTo(Category::class);
   }

   public function finishSheen () {
      return $this->belongsTo(Category::class);
   }

   public function scopeNewWoodProjects($query)
   {
      return $query
         ->where('created_at', '>=' , Auth::user()->last_login_date)
         //->where('user_id', '=', Auth::user()->id)
         ->orderBy('name','DESC');
   }


}
<file_sep><?php

use Illuminate\Database\Seeder;

class ProfilesTableSeeder extends Seeder
{

    /**
     * Auto generated seed file
     *
     * @return void
     */
    public function run()
    {
        

        \DB::table('profiles')->delete();
        
        \DB::table('profiles')->insert(array (
            0 => 
            array (
                'id' => 1,
                'user_id' => 1,
                'first_name' => 'Admin',
                'last_name' => 'Istrator',
                'telephone' => NULL,
                'image' => NULL,
                'frontendStyle' => 'slate',
                'backendStyle' => 'bootstrap',
                'date_format' => 1,
                'landing_page_id' => '41',
                'rows_per_page' => 15,
                'display_size' => 'normal',
                'action_buttons' => '1',
                'author_format' => '1',
                'alert_fade_time' => 5000,
                'created_at' => '2017-12-28 10:27:35',
                'updated_at' => '2017-12-28 10:27:35',
            ),
            1 => 
            array (
                'id' => 2,
                'user_id' => 2,
                'first_name' => 'Stephane',
                'last_name' => 'Leroux',
                'telephone' => '613-370-0275',
                'image' => '1517413947.jpg',
                'frontendStyle' => 'slate',
                'backendStyle' => 'bootstrap',
                'date_format' => 1,
                'landing_page_id' => '41',
                'rows_per_page' => 15,
                'display_size' => 'normal',
                'action_buttons' => '1',
                'author_format' => '1',
                'alert_fade_time' => 5000,
                'created_at' => '2017-12-28 10:28:06',
                'updated_at' => '2017-12-28 10:28:06',
            ),
            2 => 
            array (
                'id' => 3,
                'user_id' => 3,
                'first_name' => 'Stacie',
                'last_name' => 'Haynes',
                'telephone' => '613-327-4722',
                'image' => NULL,
                'frontendStyle' => 'slate',
                'backendStyle' => 'bootstrap',
                'date_format' => 1,
                'landing_page_id' => '41',
                'rows_per_page' => 15,
                'display_size' => 'normal',
                'action_buttons' => '1',
                'author_format' => '1',
                'alert_fade_time' => 5000,
                'created_at' => '2017-12-28 10:28:26',
                'updated_at' => '2017-12-28 10:28:26',
            ),
            3 => 
            array (
                'id' => 4,
                'user_id' => 4,
                'first_name' => 'Hugues',
                'last_name' => 'Leroux',
                'telephone' => '613-71-1454',
                'image' => NULL,
                'frontendStyle' => 'slate',
                'backendStyle' => 'bootstrap',
                'date_format' => 1,
                'landing_page_id' => '41',
                'rows_per_page' => 15,
                'display_size' => 'normal',
                'action_buttons' => '1',
                'author_format' => '1',
                'alert_fade_time' => 5000,
                'created_at' => '2017-12-28 10:28:26',
                'updated_at' => '2017-12-28 10:28:26',
            ),
            4 => 
            array (
                'id' => 5,
                'user_id' => 5,
                'first_name' => 'Luc',
                'last_name' => 'Leveille',
                'telephone' => '613-123-4567',
                'image' => NULL,
                'frontendStyle' => 'slate',
                'backendStyle' => 'bootstrap',
                'date_format' => 1,
                'landing_page_id' => '41',
                'rows_per_page' => 15,
                'display_size' => 'normal',
                'action_buttons' => '1',
                'author_format' => '1',
                'alert_fade_time' => 5000,
                'created_at' => '2017-12-28 10:28:26',
                'updated_at' => '2017-12-28 10:28:26',
            ),
        ));
        
        
    }
}<file_sep><?php

namespace App\Http\Controllers\Darts\Cricket\Players;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
use Session;
use App\Dart;
use App\DartScore;
use App\User;


class ScoresController extends Controller
{
   

   public function index($gameID)
   {
      $game = Dart::find($gameID);
      return view('darts.cricket.scores.players.index', compact('game'));
   }

}<file_sep><?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Kyslik\ColumnSortable\Sortable;

class Invoice extends Model
{
	use Sortable;

	protected $fillable = [
		'client_id',
		'notes',
		'status',
		'amount_charged',
		'hst',
		'sub_total',
		'wsib',
		'income_taxes',
		'total_deductions',
		'total',
		'invoiced_at',
		'paid_at'
	];

	public $sortable = [
		'id',
		'status',
		'created_at',
		'amount_charged',
		'hst',
		'sub_total',
		'wsib',
		'income_taxes',
		'total_deductions',
		'total',
		'invoiced_at',
		'paid_at'
	];

	protected $dates = [
		'created_at',
		'updated_at',
		'deleted_at',
		'invoiced_at',
		'paid_at'
	];

	// public function getHST() {
	// 	return number_format((float)$this->amount_charged * 0.13, 2, '.', ' ');
	// }

	// public function getTotal() {
	// 	$result = DB::table('invoices')->selectRaw('sum(hst)')->get();
	// 	return $result;
	// }

	// public function getWSIB() {
	// 	return $this->amount_charged * 0.06;
	// }

	// public function getIncomeTaxes() {
	// 	return $this->amount_charged * 0.26;
	// }

	// public function getSubTotal() {
	// 	return number_format((float)$this->amount_charged + $this->hst, 2, '.', ' ');		
	// }

	// public function getTotalDeductions() {
	// 	return number_format((float)$this->wsib + $this->income_taxes, 2, '.', ' ');

	// }

	// public function getNetTotal() {
	// 	return number_format((float)$this->amount_charged - $this->wsib - $this->income_taxes, 2, '.', ' ');
	// }

	// An invoice belongs to a client
	public function client()
	{
		return $this->belongsTo('App\Client');
	}

	// An invoice has many items
	public function invoiceItems() {
		return $this->hasMany('App\InvoiceItem')->orderBy('id','desc');
	}

}
<file_sep><?php

namespace App;

use Illuminate\Database\Eloquent\Model;
//use OwenIt\Auditing\Auditable;
//use OwenIt\Auditing\Contracts\Auditable as AuditableContract;
use Auth;
use Carbon\Carbon;

class Post extends Model // implements AuditableContract
{
	//use Auditable;
	
	// 1 category belongs to many posts
	// a related entry needs to be added to the category model
	public function category()
	{
		return $this->belongsTo('App\Category');
	}

	public function tags()
	{
		return $this->belongsToMany('App\Tag');
	}

	// public function comments()
 //   {
 //   	return $this->hasMany('App\Comment')
 //   		//->where('approved','=',1)
 //   		->orderBy('created_at','desc');
 //   }

	public function comments()
	{
		return $this->morphMany('\App\Comment', 'commentable')->orderBy('id','desc');
	}

	public function user()
	{
		return $this->belongsTo('App\User');
	}

   public function scopeNewPosts($query)
   {
      return $query
         ->where('created_at', '>=' , Auth::user()->last_login_date)
         //->where('user_id', '=', Auth::user()->id)
         ->orderBy('title','DESC');
   }

   public function scopePublished($query)
   {
      return $query->where('published_at', '<', Carbon::now());
   }

	// public function modified_by()
	// {
	// 	return $this->belongsTo('App\User');
	// }

	// public function isAdmin() {
	// 	if (Auth::user()->level == 100) {
	// 		return true;
	// 	}
	// }
}<file_sep><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Client;
use App\Invoice;
use App\InvoiceItem;
use App\Product;

class InvoicerController extends Controller
{

	public function index()
	{
		return view("invoicer.index");
	}

   public function dashboard() 
   {
      $clients = Client::orderBy('company_name','asc')->get();
      $invoicesTotal = Invoice::all();
      $invoicesLogged = Invoice::where('status','logged')->get();
      $invoicesInvoiced = Invoice::where('status','invoiced')->get();
      $invoicesPaid = Invoice::where('status','paid')->get();
      $invoiceItems = InvoiceItem::all();
      $products = Product::all();
      
      return view('invoicer.dashboard.index', compact('clients', 'invoicesTotal', 'invoicesLogged', 'invoicesInvoiced', 'invoicesPaid', 'invoiceItems', 'products'));
   }


}
