Generating nested resource with same directory structure in laravel 4 - php

Sorry if I am asking a silly question here, but I have googled it a lot and couldn't find any satisfactory answer.
I have some experience with codeigniter and I am new to laravel.
I have just installed laravel and jeffrey way generator tool. I am first working on my back-end admin panel, so what I need is to create nested resources so it will map to domain.com/admin/SomeController
But while using php artisan generate:resource country --fields="name:string, status:boolean"
It is working fine. but generating controllers, models, views etc in respective root directory and controller name should also be changed to support nested controllers
I want to create all these in some meaningful directory structure
App/controllers/admin/AdminCountryController.php
App/models/admin/Country.php
App/views/admin/country/index.blade.php etc.
I also checked generator tool documentation but couldn't find these details.
So I want to know how can it be achieved using generator or I have to do it manually.
If I chosen wrong path please tell me as I am at very initial phase of my project and my application structure will depend on it.

You need to create first that directory. For example, you want a controller app/controller/admin/AdminController.php, first create the admin folder on app/controller, then you can do php artisan generate:controller admin/adminController.php.
I am not sure if this coulde be done using Resouce.
Also routing in laravel is different with routing in CI. CI depends on domain.com/controllerClass/method/args and laravel is different.

Related

For a site built on CodeIgniter that is already deployed, is there a way to know which PHP file on the view the generate the HTML of each page?

I am currently working on site built by another developer on CodeIgniter. I do not have the GitHub repository since there is no way to reach the previous developer. All I have now is the project files stored in the file system of the host. I found the view folder of the project and see a bunch of PHP files on it. The codes of each PHP files look similar, I am having trouble knowing which PHP files generate which page.
My question is, on the browser, is there a way to know which PHP files generate the HTML of the page that I am currently viewing?
In CodeIgniter, Controllers are the routes generally. Look in the controllers directory. For example User controller with update method will result in /user/update route. Moreover, the developer might have specified custom routes too. You will have to check application/config/routes.php too. Once you will locate the correct controllers, you can find the views used by the related controllers (or routes). I hope this helps.
You cannot use the "view" files to quickly figure out what URL displays that file. It's entirely possible that any given "view" file is used on multiple pages. It's also quite likely that any given URL will use multiple "view" files.
You should instead examine the files under /application/controllers and look for lines of code making a call to $this->load->view('some_file_name_here'); There may or may not be a subdirectory as part of the file name - depends on how the original dev organized things.
The CodeIgniter documentation is excellent and is found HERE. Start with the General Topics. In particular, the following general topics (in the order shown) may be highly useful and help you make sense of what the other answers are talking about.
Controllers
Views
CodeIgniter URLs
URI Routing
Models
A read-through of the tutorial will be helpful too after checking out the above.
Use the Libraries section of the docs to get details on the various parts of the framework you're likely to run into in your explorations.

Laravel output source controller, model and view file path in all view source?

I've taken over management of a large complex site with multiple laravel installations of various ages. Some are in use some are only partially so for some routes (complex htaccess redirects abound).
I'm new to Laravel so this is a bit of a headache for me.
Is there an easy way to have laravel include the source path and filename of the controller, model and view it has used when rendering a view so I can find what files on the server are responsible for what 'pages' on the site?
TY
If you have a relative small site (i.e. a handfull of pages) you can visit each page with Laravel debugbar activated. In my office we use this for a while now and we are pretty positive about it. There is a special 'views' tab that enables you to see which views are included when you visit a certain page. It has some nice options, you can even view queries!
Example from our development environment with APP_DEBUG=true in the .env file:
In addition to the debugbar, you can also consider a package that shows route information for you by listing all routes that are called and showing the names of controllers, methods and request type in an other colour. We use Pretty routes since it is more convenient for us to read all 'routes' in the browser than in the terminal.
When starting from the app/ directory, the path of any of these classes is the same as the namespace they are in.
So if you have a model App\Models\User, this will be located in app/models/User.php.
As for the views, you start in the resources/views/ directory, replace dots in the view name by / and add .blade.php.
So, a view named website.index is located in resources/views/website/index.blade.php.
This is kind of an advanced answer that requires some Linux skills, but with the built in commando strace you can see which resources are opened: which php file, which database calls etc. This way you can analyze what is used when.
A very good tutorial can be found here:
https://hackernoon.com/debugging-a-php-application-with-strace-4d0ae59f880b
another great article on strace with PHP: https://ma.ttias.be/linux-application-script-debugging-with-strace/
I would also suggest to use all kind of filters and grep to filter the output to something meaningful.

Using Laravel with an existing website

I have an existing website running on PHP, MySQL CSS, JS and Ajax.
For future projects, I would like to use the Laravel framework to create new pages or functionality to the existing website... let's say a blog, for instance.
Is this possible?
Is the Laravel framework compatible with an existing website that is not set up using the MVC framework?
The reason is that I would like to make my work easier and more efficient and the use of a framework would be helpful.
Please let me know if you need any other info, I know the question is a little broad.
Thanks,
Justin
yes it's possible but of course maybe with difficulties.
you should put your web files in /views directory, convert your php files to controllers or library files and put your assets in /public directory.
then you can assign routes to your controller and call it form outside of the application.
main job is put your code into controller or libraries. is it possible to split your code into separate logical units? and extract model logic (as php mvc says) from your main code.
so if you have a clean code with good design and minimum dependencies you can think more about it. this could be a good challenge if you go through it cautiously. be careful to not fail and waste your time.

Use Laravel internals in another php website

I have an interesting question regarding Laravel.
I am building a control panel with certain functionality with Laravel 5.
This control panel will work standalone in a subdirectory of any another PHP website.
Here is how the folders tree looks like:
/index.php
/(other php files from the main project)
/controlpanel (Laravel)
I want to use the Laravel functionality within the main PHP project.
For example I want to be able to query the database of the control panel with Eloquent models from within /index.php.
Something like limited Laravel (without routers, etc).
I have tried to include the bootstrap/autoload.php and call Eloquent model, but the IoC Container is not instantiated and it's not working.
I hope someone can point me to the right direction.
You can use some of Laravel's packages outside the framework, however it takes some doing in most cases.
Laravel Illuminate Router Package In Your Application
Use Eloquent Outside of Laravel
The resources above are for Laravel 4, but you could use them as a starting point as they might be very similar to the approach needed for Laravel 5 packages.

Laravel Existing Database

I have a database we use on some of our existing websites, sites were built in Yii framework by another developer so no Laravel, I have set up a new project using laravel but am looking for the best way to link up to that database and return the information.
linking to the database is easy enough, just change the database.php file but I am getting really confused with migrations part and how to call it into a webpage.
So what's the simplest way to go about doing this?
Migrations are used to create or modify database structure. Since you already have a database set up, you don't need to use migrations.
To get accustomed with Laravel I strongly suggest watching:
Laracasts - Laravel 5 Fundamentals
I also suggest you go over the entire Laravel Documentation just to get acquainted with all the framework has to offer.

Categories