Laravel 4.2 Controller Subfolder routing

This is a simple way to organize your controller files or create sub folder under the controller folder.

1

After you created the folder, controllers and setup your routing. Then you need to run this into your command prompt.
otherwise you’ll encounter  this error message.

ErrorException (E_WARNING). failed to open stream: No such file or directory

Run this script

artisan dump-autoload

artisan

 

 

Moving Image from current directory to another using Laravel 3.2

I have one task that will move the product images to one folder.
I have create and validate it using Laravel 2.2 Framework.This will get all the product images validate if the picture existed to the directory if not then display the no.png image otherwise copy the file and move it to the new directory.

$rsProduct = Products::get_ProductByCategoryId2($categoryList->id); // I am getting the records set of the products

$pathFolder = path('public').'menu/'.Products::urlReplaceDefault($categoryList->category_name);

if (!file_exists($pathFolder))
{
mkdir($pathFolder, 0777);
}

echo $categoryList->category_name;

foreach($rsProduct as $item)
{

$urlPath = path('public'). "/path/to/pictures/thumb/".$item->pic;

$newFilename = "";
if (!file_exists( $urlPath ) )
{
$urlPath = path('public'). "/path/to/pictures/thumb/no.png";
$newFilename = Products::urlReplaceDefault($item->title).".png";
}
else
{
if ($item->pic!="")
{
$newFilename = explode('.', $item->pic);
$extension = $newFilename[1];

$newFilename = Products::urlReplaceDefault($item->title);
$newFilename = $newFilename . "." . $extension;

}
else
{
$urlPath = path('public'). "/path/to/pictures/thumb/no.png";
$newFilename = Products::urlReplaceDefault($item->title).".png";
}
}

copy($urlPath, $pathFolder."/".$newFilename);

}

 

Laravel 4.2 Login Auth via jQuery Ajax

My colleague design the login that pops up.

Here is my Javascript

// JavaScript Document Tabs 01
$(document).ready(function() {
	$('#formPopupLogin').submit(function(){
		 $.ajax({
	        type: "POST",
	        url: $(this).attr('action'),
	        dataType: "json",
	         data     : $(this).serializeArray(),
	         success: function(data) {
	            if (data.status) { 
// Success this should redirect or refresh the page. 
document.location.reload(true);
				} 
	            else {
				$('.errorWithLogin').html(data.errorMessage);
				$('.errorWithLogin').removeClass('hide');
	            }
	        },
	        error: function()
	        {
	            $('.errorWithLogin').html(server_error_message);
				$('.errorWithLogin').removeClass('hide');
	        }
	    });

		return false;
	});

});

and here is my controller function

public static function authLogin()
	{
		$input = Input::all();

		// Entry Record 
		$dataRecord = array('Username'=>$input['txtUsername'],
					'Password'=>$input['txtPassword']);

		// For my Future used
		$session_id  = Session::getId();

		// Validation
		$validator = Validator::make($dataRecord, User::$rulesLogin);

		// Intialize Arayy 
		$data = array();
		$data['status'] = 0; // Reload the page success 
		
		if ($validator->fails())
		{
			$htmlContent = "";
			$errors = $validator->errors()->getMessages();

			foreach ($dataRecord as $key => $value) {
				 $htmlContent .= "<p>".$errors[$key][0]."</p>"; /// I checked the result it is always zero // Then I assume that this display only zero // Lazy me. 
			}
			
			$data['errorMessage'] =  $htmlContent;
		}
		else 
		{	
			$rememberMe = false;	
			// Design doesn't capture remember me. 
			// So I remove it. 
			// if (isset($input['remember']))
			// {
			// 	$rememberMe = true;
			// }
			
			// validate the credentials 

			if (Auth::attempt(array('username' => $input['txtUsername'], 
									'password' => $input['txtPassword'], 
									'status'=>'1'), $rememberMe))
			{	
					
					if (Auth::check())
					{
						
					}

					$data['status'] = 1; // I assume that when status is success then I can reload the page / or do some redirection 
			}
			else 
			{	
					$data['errorMessage'] =  trans('messages.LOGIN_LOGIN_DOES_NOT_EXIST');
			}

		}

		response()->json($data);
	}