In most case, we want to extend our Laravel applications capabilities by adding helper class.
It is not a best practice to insert this classess inside Controller and Model.
so we have to write our classess in separate files and group it by folder
Here let us have a look how we add helper classess in laravel
1. We have app folder on root folder of laravel.There we can create a Libraries folder inside app folder.
2. We can create a class/helper file and we can write a our custom class there, on the top of custom class we have to define namespace our_folder_name;
namespace our_folder_name
for example ,
//here my folder name is Libraries
namespace Libraries;
class className{
//class methodes
}
Now we can go to our controller and on top we can include our helper class
use Libraries\filename as filename;
And we can go to compser, inside autoloder we can add “app/foldername”
All my samples files are given below
Library/className.php
<?php
namespace Libraries;
class className{
//class methodes
function testmesthode(){
return "Hello world";
}
}
testController.php
<?php
use Libraries\className as className;
class testController extends BaseController {
function index(){
$test = new className();
echo $test->testmesthode();
}
}
Today i was trying to install laravel in MAMP , While going through their step on laravel site mentioned i found that i didn installed mycript extension. I had googled for lot of time and lastly i installed .
I am writing this will help some one to install laravel in Mac using MAMP.
Install composer
Before installing laravel we have to install composer . We can go to https://getcomposer.org/ and we can install from from there or we can follow the following steps step
1. first we have to check curl is enabled . step 2. we can install composer globally as mentioned in their site