Showing posts with label laravel 4. Show all posts
Showing posts with label laravel 4. Show all posts

Thursday, November 21, 2013

laravel 4 Cannot modify header information - headers already sent by (output started at

This error happened when you are using one of these statements in laravel 4 application :

 Redirect::to or  header('Location: ' . $url) 

Where your Laravel 4 application had sent a header to the screen before you decide to redirect the browser to other url . Sometimes this error caused by echo statement before the redirection , other output text or white space, But in my case the error because I have added a php closed tag:

?>  

in the end of the included files. So removing  this tag will bring the application back to normal behavior.

Saturday, October 19, 2013

The Response content must be a string or object implementing __toString(), "boolean" given. Laravel4

"The Response content must be a string or object implementing __toString(), "boolean" given. Laravel4" .

This kind of error will kill you if yo are going to debug it Or trace it step by step, you will never find the solution because this error happens in response, I mean that it will be detected by the framework only after the response is ready to be rendered ,So it is as the message said "the response is boolean". Often it will happen in the view that some variables affect the response content . Just check the view variables one by one ,and remove each of them the try to run again . you will find the variable that cause this error. But before going in this path try to change the view by any other view page (blade-template) and see if the error is still there . if it is not , then the problem in the view page.

Sometime this error caused by directly returning false :

 
return false ;
Just change it to :
return 0;

Saturday, August 17, 2013

SQLSTATE[42S02]: Base table or view not found: 1146 Table - Laravel Eloquent

If you got this error and you know for sure  that you are having the table name in your  database, Then the problem is the prefix of the table, why is that ?
I have my model declared like this :

class tableName extends Eloquent{} 

Now eloquent will take in account that table name in the database is table_names , As you see, it will add underscore before the capital letter and "s" for plural .this will happen by default unless you explicitly declare the name of the table inside the model class like this:

class tableName extends Eloquent{

protected $table = 'tableName'; 


}

Or Avoid the Capital letter in the name of the model.

Tuesday, July 23, 2013

Adding new classes or library to laravel 4

The ugly, lazy and awful way: At the end of bootstrap/start.php , add an include('tools.php') and place your function in that new file.



The clean way: Create a library. That way it'll be autoloaded ONLY when you actually use it.
  • Create a library folder inside your app folder
  • Edit start/global.php to add app_path().'/library' to the ClassLoader::addDirectories( array.
  • Edit composer.json to add "app/library" to the autoload array.
  • Run composer dump-autoload
  • Create your library file, create a class in it, and add static functions to it
  • Call your class and static functions from your views.
Credit goes to this guy