Skip to content

AngularJS and Laravel5: Retrieve data from the database

Today I would will like to show you how to use Angular JS in Laravel5 and I will show you how to get data from the database in Laravel5 using Angular JS.

Here my table structure:

CREATE TABLE  `posts` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;  

Model : app/post.php


Controller :app/http/controllers/PostController.php


View : resources/views/angualr_demo.blade.php



    
        
        
        
        arjunphp.com - Laravel - Angular JS

        

        
        

        
        
        
    
    
        

        
S.no. Name
{{post.id}} {{post.name}}

Laravel’s Blade templating engine and Angular use the same markup when displaying variables.Both Laravel and Angular use the double curly brackets {{ name }}. we can fix this by changing laravel blade tags by using Blade::setContentTags(),Blade::setEscapedContentTags().

    Blade::setContentTags('<<', '>>');        // for variables
    Blade::setEscapedContentTags('<<<', '>>>');   // for escaped variables data

I usually place this in my routes.php file.

Routes : app/Http/routes.php

Blade::setContentTags('<<', '>>');        
Blade::setEscapedContentTags('<<<', '>>>');   
Route::get('/', 'postController@index');
Route::get('post/get_list', 'postController@posts');

That's it.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments