Displaying HTML with Blade shows the HTML code

I have a string returned to one of my views, like this: $text=”<p><strong>Lorem</strong> ipsum dolor <img src=”images/test.jpg”></p>” I’m trying to display it with Blade: {{$text}} However, the output is a raw string instead of rendered HTML. How do I display HTML with Blade in Laravel? PS. PHP echo() displays the HTML correctly. 20 Answers 20

Get the Last Inserted Id Using Laravel Eloquent

I’m currently using the below code to insert data in a table: <?php public function saveDetailsCompany() { $post = Input::All(); $data = new Company; $data->nombre = $post[‘name’]; $data->direccion = $post[‘address’]; $data->telefono = $post[‘phone’]; $data->email = $post[’email’]; $data->giro = $post[‘type’]; $data->fecha_registro = date(“Y-m-d H:i:s”); $data->fecha_modificacion = date(“Y-m-d H:i:s”); if ($data->save()) { return Response::json(array(‘success’ => true), 200); … Read more

PDOException SQLSTATE[HY000] [2002] No such file or directory

I believe that I’ve successfully deployed my (very basic) site to fortrabbit, but as soon as I connect to SSH to run some commands (such as php artisan migrate or php artisan db:seed) I get an error message: [PDOException] SQLSTATE[HY000] [2002] No such file or directory At some point the migration must have worked, because … Read more

Rollback one specific migration in Laravel

I want to rollback only : Rolled back: 2015_05_15_195423_alter_table_web_directories I run php artisan migrate:rollback, 3 of my migration are rolling back. Rolled back: 2015_05_15_195423_alter_table_web_directories Rolled back: 2015_05_13_135240_create_web_directories_table Rolled back: 2015_05_13_134411_create_contacts_table I delete both of my web_directories and my contacts table unintentionally. I never want that to happen, and if I can rollback only that specific … Read more

Laravel Add a new column to existing table in a migration

I can’t figure out how to add a new column to my existing database table using the Laravel framework. I tried to edit the migration file using… <?php public function up() { Schema::create(‘users’, function ($table) { $table->integer(“paid”); }); } In terminal, I execute php artisan migrate:install and migrate. How do I add new columns? 17 … Read more

How to Create Multiple Where Clause Query Using Laravel Eloquent?

I’m using the Laravel Eloquent query builder and I have a query where I want a WHERE clause on multiple conditions. It works, but it’s not elegant. Example: $results = User::where(‘this’, ‘=’, 1) ->where(‘that’, ‘=’, 1) ->where(‘this_too’, ‘=’, 1) ->where(‘that_too’, ‘=’, 1) ->where(‘this_as_well’, ‘=’, 1) ->where(‘that_as_well’, ‘=’, 1) ->where(‘this_one_too’, ‘=’, 1) ->where(‘that_one_too’, ‘=’, 1) ->where(‘this_one_as_well’, … Read more

How to create custom helper functions in Laravel

I would like to create helper functions to avoid repeating code between views in Laravel. For example: view.blade.php <p>Foo Formated text: {{ fooFormatText($text) }}</p> They’re basically text formatting functions. How should I define globally available helper functions like fooFormatText()? 22 s 22 Create a helpers.php file in your app folder and load it up with … Read more

How can I remove a package from Laravel using PHP Composer?

What is the correct way to remove a package from Laravel using PHP Composer? So far I’ve tried: Remove declaration from file composer.json (in the “require” section) Remove any class aliases from file app.php Remove any references to the package from my code 🙂 Run composer update Run composer dump-autoload None of these options are … Read more