0

currently I have a standard Laravel 5 proyect, eg:

 Laravel Directory
     app Directory
     bootstrap Directory
     config Directory
     database Directory
     public Directory
     resources Directory
     routes Directory
     storage Directory
     tests Directory
     vendor Directory

what I'm trying to do is to take the public and resources folder out from the application and put it them on a different project, and in that way I'll use the laravel part only for backend purposes and the frontend parte I'll manage it on an outside project. e.g.:

 Laravel Directory
     app Directory
     bootstrap Directory
     config Directory
     database Directory
     routes Directory
     storage Directory
     tests Directory
     vendor Directory

Frontend project
     index.html
     app folder
     css folder
     assets

Any recomendation or ideas to do it ?

2
  • 2
    So many question to myself. Want to ask you a few things. Backend meaning you want to use only console application or you want to create api from laravel? Suggestion, if you don't want to use view file, you no need to take out. Just leave it. Commented Dec 9, 2016 at 6:23
  • I want to create api from laravel to be consumed from another project apart, but I haven't found a solution for what I want, maybe its just not possible, but I think the "Just leave it" would it be the best option foe now Commented Dec 9, 2016 at 6:41

1 Answer 1

11

Removing (or moving) the Public folder is not a good idea, especially due to the fact that the public/index.php file is the entrypoint for the application.
I personally use both laravel and lumen for a bunch of my REST-API's and it works great, so that thought is not at all wrong.
Just ignore the views, don't use them and don't expose them from any controller action, but rather return all data from the controllers as JSON instead.

This is easily done from the controller actions like:

public function getSomethingAction() {
    return response()->json([
        "some" => "property"
    ]);
}
// Which will produce the following json (including headers and all):
{
    "some": "property"
}

I would also recommend that you group your routes under a API namespace of some sort:

Route::group(["prefix" => "api/v1"], function() {
    Route::get('something'...
});

So now when you call domain.tdl/api/v1/something you will get a neat json response!

Sign up to request clarification or add additional context in comments.

1 Comment

this is just the answer that I was looking for!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.