Skip to main content

Featured

Host Laravel project on cPanel

Step 1:- First of all, we have to get all the files & directories into laravel_project folder. open your terminal & go inside your project folder,  And run the command  php artisan cache:clear . to clear your cache. then run  php artisan config:clear to clear the cached version of your config file, if there is any. Now make a zip folder of your project’s folder for ex. Laravel_project Step 2 : – Upload your folder After login to your cPanel, for uploading folder go to File Manager, & upload your folder in root directory, i have created laravel_project folder in root directory.   Step 3 :-             Unzip (your project’s folder) laravel_project  open laravel_project folder and move all the public folder content into public_html directory. so make sure that, you do not have to keep anything in public folder, it should be blank. Step 4 :- keep .htaccess file into public_html & into (your created folder) laravel_project that is outside the public_htm

how to add custom attribute in controller laravel

Why not in model? Eloquent has a great feature called “Accessors”. The feature allows you to add custom fields to models that don’t exist on the model or in the table.

function getFullNameAttribute() {
    return sprintf('%s %s', $this->first_name, $this->last_name);
}

Now you have access to a full_name attribute on the model, same as you mentioned:

$user = User::find(1);
$user->full_name;

Comments