Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

backend/frontend separation in laravel

I come from a Codeigniter background. At the moment I am building a CMS in Laravel.

What I would like to know is how can I separate the backend and frontend in Laravel?

In Codeigniter i use to make two controller Admin_Controller and Front_Controller.

Article extends Admin_Controller
Article extends Front_Controller

and the file structure looked like this

controller
--admin
---user
---blog
---news
--user 
--blog
--news

for admin controller I make separate folder and front end controller remain in root of controller folder.

Should I use the same logic in Laravel or is there a better way to do it?

like image 624
Dexture Avatar asked Feb 19 '14 13:02

Dexture


People also ask

Should backend and frontend be separated?

With a separate frontend and backend, the chances of breaking the entire website are significantly low. It is also relatively easier to debug since it is clear from the start whether there is an issue in the frontend or backend. Upgrading your web applications makes them faster and reduces the risk of bounces.

Is Laravel used for frontend or backend?

Laravel is a backend framework that provides all of the features you need to build modern web applications, such as routing, validation, caching, queues, file storage, and more.

Which front end is best for Laravel?

Vue. js is officially supported by Laravel, and Angular and ReactJS are also often the recommended frontend frameworks to use alongside a Laravel backend.


1 Answers

If you want to create thinks like Taylor Otwell and 'the core' is trying to teach people do things in Laravel, this is a good start:

Your files could be organized as

├── app
│   ├── ZIP
│   │   ├── Controllers
│   │   │   ├── Admin
│   │   │   │   ├── Base.php <--- your base controller
│   │   │   │   ├── User.php
│   │   │   │   ├── Blog.php
│   │   │   │   ├── News.php
│   │   │   ├── Front
│   │   │   │   ├── Base.php <--- your base controller
│   │   │   │   ├── User.php
│   │   │   │   ├── Blog.php
│   │   │   │   ├── News.php

Configure a PSR-0 or PSR-4 (better) to autoload your classes:

"psr-0": {
    "ZIP": "app/"
},

Create namespaces to all tour classes, according to your source tree:

<?php namespace ZIP\Controllers\Admin

class User extends Base {

}


<?php namespace ZIP\Controllers\Front

class Blog extends Base {

}

And create your base controllers

<?php namespace ZIP\Controllers\Admin

use Controller;

class Base extends Controller {

}
like image 200
Antonio Carlos Ribeiro Avatar answered Oct 19 '22 00:10

Antonio Carlos Ribeiro