I would suggest an approach like Shawn does in the nextVersion branch of LaravelIO https://github.com/LaravelIO/laravel.io/tree/nextVersion/src Separates most things in it's own namespace.
Hi,
Laravel allows to put controller,models,views ,etc anywhere you want to.
Of course , You can get a structure of App like following.
# App (provided by laravel)
## Applist
### employee
#### controller.php
#### model.php
#### view.php
### schedule
#### controller.php
#### model.php
#### view.php
And, Many people do so .
It's very simple to do.
First , your package or library should follow PSR-0 or PSR-4 . And open composer.json then edit autoload . Last, execute composer dump-autoload .
For instance ,
User package's sturcture is like following.
# App (provided by laravel)
## Components
### User
#### Controllers
#### UserController.php
#### Models
#### User.php
namespace of UserController.php is '\User\Controllers '
in composer.json
"autoload" : {
"psr-0" : {
"User" : "app/componets"
}
}
then, composer dump-autoload
all done!
If you want to know more about it, reference following links.
thank you.
have a good day.
Thanks that was really helpful with what I need. Now that I have my controllers in different directories how would I go about extending the BaseController with my new controller? Should I make the baseController a global or create a namespace for that as well now? Also BaseController extends Controller, where is Controller even defined/declared?
Thanks,
I followed this video which really helped me: https://www.youtube.com/watch?v=FzdhnbM_0ug
In laravel, BaseController is autoloaded because of autoload:'classmap' in composer.json. Therefore, You can extend BaseController whenever.
for instance, UserController.php is in app/component/User/Controller .
<?php namespace User\Controller ;
class UserController extends \BaseController {
}
Should use '\BaseController' not 'BaseContoller' because the namespace of BaseContoller is global.
Controller is abstract class. It's defined in 'vendor/laravel/framework/src/Illluminate/Routing/Contoller.php' .
You're awesome, that is exactly what I was looking for! I'm almost there. Now, I have one last question; how do I get access to the View class? I tried using the '' that worked with BaseController but no luck. Thanks for taking your time to help me so much.
I am setting up like this:
## Applist
### login
#### controller.php
#### model.php
#### view.php
### homepage
#### controller.php
#### model.php
#### view.php
<?php namespace appList\login ;
class LoginController extends \BaseController
{
public function __construct()
{
//dd('Hello');
}
public function showLogin()
{
return \View::make('view');
}
}
P.S. I am still going to use the views folder to hold my layout templates and just have my app\appList\login\view.php provide the content.
Hi Farr433,
If you simply add use View; below your namespace declaration everything should work fine with regards to the View Facade. You may also then remove the .
May I ask if your using PhpStorm? If so, it's likely you won't get auto-completion or your IDE may also be telling you that it cannot find the View Facade. This is in fact because it is a Facade but there is a solution.
There is a git repo called Laravel-IDE-Helper written by barryvdh or you can download the gist from the link below.
Simply create a file called '_ide_helper.php' in the root of your project and paste the code inside and everything should work fine.
Hope that helps.
Thanks, I am using php storm and this makes it a lot easier now. I just recently switched from dreamweaver and have been missing out on a lot to say the least! I am now properly displaying pages as I would expect and can get to the good stuff.
Thanks for everything guys!
I'm sorry guys, I have yet another question. I have noticed that I have to manually connect all of the Facades using:
use View;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Redirect;
What is the easiest way to be able to utilize Facades and etc without always having to import them? Should I maybe make an abstract appList class and then have an app like login extend the abstract class or what would be the best way to go about that?
Thanks,
Anthony
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community