Laravel 5 belongsToMany() by Using Pivot Table Example

Relationship using pivot table in Laravel 5? A method, belongsToMany(), is a part of Eloquent ORM in Laravel 5. It connects between tables and it has many to many relationship. In order to use it, you must have two models three tables.

Continue reading Laravel 5 belongsToMany() by Using Pivot Table Example

Blade Template Doesn’t Work in Laravel 5

No, that’s not true the Blade Template is still working in Laravel 5, but its tag directive has been changed. For some of you who don’t read the Laravel development change log may not know about this. The documentation said that “For better security by default, Laravel 5.0 escapes all output from both the {{ }} and {{{ }}} Blade directives”. So, what is the new directive?

Continue reading Blade Template Doesn’t Work in Laravel 5

How to Add Form Class in Laravel 5

Many of you will question about the error like HandleExceptions->fatalExceptionFromError( array('type' => '1', 'message' => 'Class 'Form' not found' or
FatalErrorException in 193a332e9290704ad006bafdbd047286 line 2: Class 'Form' not found
. Hmm, you must be just upgrading your Laravel 4 to Laravel 5 weren’t you?

Laravel 5 doesn’t include the Form class like the previous version. It doesn’t matter why, but I think it loses great its great feature. Then, how to make it available like Laravel 4? Several steps are needed to get it work.

Continue reading How to Add Form Class in Laravel 5

How to Change public To public_html On Laravel 5 Ubuntu

Laravel 5 has different level from previous version. It becomes simpler and it has different file structure. That was making me confused at the first time when I was trying to migrate from previous version. The odd is bootstrap/paths.php doesn’t exist anymore. Now, how do I set the public folder of my project to desired one?

I thought it was simple, but lately I can’t find the settings are. I found it blank page after I changed the public folder to public_html. Then I tried to look up the public/index.php. I found something interesting about how it processes the index.php itself. It made me come to the conclusion that I don’t need to set any configuration to get public folder to public_html works.

Then why I saw the blank page? Well, I am not a programming Guru, but I knew what’s happening there. It looks like Laravel processes it files first before it’s ready to be served to users. That’s why Laravel need folder to store the processed files. It is called storage folder.

I checked the storage and I found it has no write permission for the application. So, I changed it to 777 recursively. Then, it works.

Damn. I forgot to mention that I was using Apache web server to serve Laravel 5. But, if you are going to use php artisan serve command all I’ve mentioned above won’t work. Instead, use the Wood Marks way. Thanks to him.

Count Number of Files and Folders in a Directory Using Terminal

I Googled so much and can’t find any simpler method to count files or folders in a directory in Linux. I am using Ubuntu 14.04. If it’s only files and folders, it would be simple.

Count Files and Folders

$ ls -l | wc -l

The wc -l command is read “WordCount lines”. It means after you executed the ls, the corresponding result will be counted by it’s line. For example, if you are using ls in your working directory, say there are 2 files and 2 folders, it will return 4 lines. If you add it becomes ls -a, it will return 2 more lines. So, it returns 6 lines because of “.” and “..” are counted.

Continue reading Count Number of Files and Folders in a Directory Using Terminal

Changing Directory and Files Permission Recursively in Linux

I’ve discovered the hidden treasure at superuser to change the permission of directories or files recursively in a folder. Not quite simple, but straight. To recursively give directories read & execute privileges:
Continue reading Changing Directory and Files Permission Recursively in Linux

My Gruntfile.js Content Using Compass and Watch

Now, say you don’t know how to create Gruntfile.js manually just like I was. You’re desperately want to use Compass (grunt-contrib-compass) and Watch (grunt-contrib-watch) to develop your project. First, you have to install it in your project folder as node_modules:

$ npm install grunt-contrib-compass grunt-contrib-watch

That will install the Compass and Watch into node_modules directory in your project folder. Yes, it’s installed locally.
Continue reading My Gruntfile.js Content Using Compass and Watch

NPM Global As Reference of NPM Local

How to refer NPM Local to NPM Global? If you don’t want to install the packages locally because it’s wasting hardisk space you can use the packages which have globally installed.

For example, you install the sass package globally:

$ sudo npm install -g grunt-contrib-sass

You don’t want to do the same for your project, project, and another project because you think the files are the same but just the locations which make it different.

So, in case we want to install sass package from global to local we can use link directive in your project folder:

$ npm link grunt-contrib-sass

It will automatically create node_modules/grunt-contrib-sass link to grunt-contrib-sass global package. Piece of cake.

Installing Node.js, NPM, Grunt, and Yeoman in Ubuntu 14.04 LTS

Installing Node.js is not as difficult as a year ago. You can simply install it through your Terminal. First get the installer.

$ curl -sL https://deb.nodesource.com/setup | sudo bash -

And then install it with apt-get.

$ sudo apt-get install -y nodejs

Continue reading Installing Node.js, NPM, Grunt, and Yeoman in Ubuntu 14.04 LTS