Categories
Laravel Samuel

simple laravel form verification

This post is simply a note of an item I did today to fix a little issue on a select form in laravel:

The issue was form verification on a select drop down box, the default value was passing the verification test since it in fact has a “Value”, solution =


update the drop down to show default wording on the front end but leave a blank value in the form field:

{{ Form::select('sales_counselor', ['' => 'Select Counselor'] + $users,

add a check to make sure the sales counselor field has a value, a check that the default value above will not pass:
'sales_counselor' => 'required|exists:users,id',

Categories
Fixing Stuff Laravel Samuel

Fixing PHP Error: Maximum function nesting level of ‘100’ reached, aborting

when copying a Laravel project from production down to my local machine today I got the following error while trying to access a specific page:

PHP Error: Maximum function nesting level of '100' reached, aborting

This was a first for me to see this, also of note I was not running this locally on wamp, I was simply serving the file with php artisan serve on windows using git bash. To fix the issue we took the following steps:

-locate the controller that powers the page generating the error (if you don’t know this off the top of your head, start back at your routes.php file). Look through the routes file unitl you find the correct controller.

-open up the controller and locate the function that is controlling the front end view (the page where your error is occurring). Next test to make sure you have the right function by adding dump and die to the top of your function:

dd($value);
*note you can also just use something like: dd('test');

-if you have the correct spot then the page will display your DD (dump and die) message. Once you confirm this then add the code below to fix the maximum function nesting error:

ini_set('xdebug.max_nesting_level', 200); //put this in here to fix local ini_set limit

That’s all there is too it. Also a side note its not a great practice to do this as a long term fix, there are probably larger issues at play that need to be addressed. But in my current case this worked perfectly and if anyone out there is running into the same issue hopefully this helps you solve it.

Categories
Laravel Samuel

Installing Laravel Spark on a new Project

These are mainly just notes copied from laravel docs. Just wanted them in this specific order so when I came looking back at them I could follow them easier:

First, download the Laravel installer using Composer:

composer global require "laravel/installer"

Make sure to place the ~/.composer/vendor/bin directory (or the equivalent directory for your OS) in your PATH so the laravel executable can be located by your system.

Next install a fresh new laravel project:

laravel new project-name

Next, add the following repository to your composer.json file:


"repositories": [
{
"type": "composer",
"url": "https://spark-satis.laravel.com"
}
],

Note: don’t add this at the bottom of the file, put it right under the require-dev section.

You should also add the following dependencies to your composer.json file’s require section:


"laravel/spark": "~1.0",
"laravel/cashier": "~6.0"

Next run the composer update command. This will add all the dependencies and clone in spark. Also note you will have to add a github token, which is stored in: C:/Users/computer-user-name/AppData/Roaming/Composer/auth.json

**Note you need to link laravel spark with your github account, and join the repo before composer will have access to clone it into your project**

Next add 2 providers to the confing/app.php file:

Laravel\Spark\Providers\SparkServiceProvider::class,
Laravel\Cashier\CashierServiceProvider::class,

Next run the spark install command:
php artisan spark:install --force
**note you must add the 2 providers into the ‘providers’ => [ section on line 124

After spark has successfully installed add the following provider to the config/app.php file again in the providers section:

App\Providers\SparkServiceProvider::class,

Now we are ready to run the DB migrations. If you get the @homestead error just update the .env file to use your local db creds.

Categories
Fixing Stuff Laravel Samuel

combining css and js files into 1 http request

install gulp onto the server:

1.) upload the files (gulpfile.js) and (package.json) into the root directory of the site (make sure to update file paths to the correct css and js directory’s first)

2.) ssh into the server and run: npm install, do this in the same root directory you just uploaded both files to. (if this errors out just manually upload all needed node_modules files to the root directory)

3.) make sure the node_modules directory and all sub directory can execute files (chmod +x directory_name -R)

4.) execute the combining script to combine all the js and css files (./node_modules/gulp/bin/gulp.js) must be run from root directory of site or else will fail

5.) change out the javascript and css script files to the new combined file for each

If all went according to plan you now limited your css and js files down into 1 http request respectively and minifid them both.

general notes:

if you upload a new file or edit a file in the css or js directory you have to ssh into the server and run:

./node_modules/gulp/bin/gulp.js

*this generates the new combined file
*would be a good item to add to a deploy script

If the page errors out (or white screens of death) explcitly define the order of the js files in your gulpfile.js. What most

Categories
Laravel Samuel

Initial Laravel Setup Checklist

This post is merely a checklist reminder for myself and not meant to be a tutorial. If you are looking for a tutorial on setting up laravel for the first time please go to:

http://www.nowordsbarred.com/setting-laravel-4-first-time-onwamp-server/

 

    1. install laravel 5 via composer (composer createproject laravel/laravel preferdist)
    2. make deploy script for server (chmod +x script after uploading it)
    3. connect server to repo with deploy keys
    4. clone repo onto production server manually
    5. create symlink to public folder of laravel
    6. install composer in laravel directory
    7. create database
    8. define DB creds in .env file

Thats all the needed steps for getting a laravel site configured on the server.

 

1.) To allow the server to connect to the Code Base repo we need to run (cd ~/.ssh). Then run (cat id_rsa.pub) and copy the pub key file (control + insert + c to copy from terminal)… maximize the SSH terminal window if getting invalid key warning from CB, spacing seem to effect this. (If no file present run ssh-keygen). Next step is login to CB, hit the repos page, then hit the gear icon > deployment keys > ad new ssh key > past key into this window and save.

2.) When you upload your deploy script file, to give it proper permissions to execute we need to run (chmod +x script-name)

3.) To create our symlink path to the public folder we want to run:
ln -s /home/user/git/repo-name/public /home/user/public_html/public_html

or if you want to install laravel in a subfolder you can run:
ln -s /home/user/git/project/repo-name/public /home/user/public_html/directory/folder-name

**Notes**
-you must delete the public_html folder if its is already present, most systems will make this folder by default when the account is created.
-you must include the full file path, including /home/username if your are on cpanel

Categories
Laravel Samuel

Random laravel notes

kept running into this strange error for a few minutes tonight, but finally got to the bottom of it.

if you are getting “reflectionException” “controllerName does not exists” this is because you already have the controller created in your route.php file. Remove it from routes.php (or comment it out the save). Now run the command again and it will succeed.

 

how to make laravel controllers via command line:

controller:make MarketingController

when there is a conflict in tortise git:

-click on the file in conflict, hit git stash
-pull down the new code
-right click on the white space in the folder (not on the actual file) hit stash pop (this will merge your stashed file with the new one)
-commit then push

 

if php artisan migrate is not working, just run php artisan migrate:refresh and it will run the latest migrations.

if you are running DB seeders and getting an error, to find out what file the error is in run: php artisan db:seed -v this will spit out the error info of what file the seeder breaks on and what line specifically breaks it.