Laravel naming convention for blade files - laravel

I know that naming conventions in Laravel is covered in another question, but blade files are not covered there. I read several blogs and forums and they all offer different approach so I want to ask here:
My controller method is AdminController#listPropertyTypes - which lists and manages the property types..
One blog suggests:
/resources/views/admin/property/types.blade.php
Another blogs suggest underscore or no space:
/resources/views/admin/property_types.blade.php
/resources/views/admin/propertytypes.blade.php
I would personally named this way since it is a view:
/resources/views/admin/property-types.blade.php
Is there a best practice or PSR rule for this?

EDIT: Laravel community mostly use kebab-case or camelCase
ie views/admin/property-types.blade.php or views/admin/propertyTypes.blade.php
Laravel's creator seems to use kebab-case, but Spatie recommends camelCase.
As #MrEduar explained it, there is no strict convention.
NB: https://www.laravelbestpractices.com website is abandonned and not affiliated with Laravel.
OLD: Initial answer
I came across Laravel Best Practices.
Laravel : Best Practices aims to put together all the resources and best practices in using the Laravel Framework. Last Updated: 2020-05-07 12:26:48
Views
You SHOULD use snake_case as file name of your Blade templates
Good
show_filtered.blade.php
Bad
showFiltered.blade.php
show-filtered.blade.php

For blade file names, there is no convention as such. But as #James says in his commentary, and I quote
If you are asking about best practices, then one suggestion would be
to strictly use CRUD controllers; AdminController#listPropertyTypes is
not CRUD. AdminPropertyTypesController#index is more "best practice".
And in this case the best way would be /resources/views/admin/property/types.blade.php.
You can read more about this in Laracon 2017 or in Adam Watham's github repository where he explains it further.
If you are not happy with this result I suggest you also use CamelCase According to the Spatie Guidelines
resources/
views/
openSource.blade.php
So, in the controller
class OpenSourceController
{
public function index() {
return view('openSource');
}
}
Instead of looking at unreliable blogs, be guided by the great minds of the Laravel community.

Related

What is the correct approach to learn Codeigniter?

In the last 3 months, i have learnt html, css, js and php and now i'm trying to learn Framework Codeigniter. My teacher gave me a rough idea abt MVC and asked me to download a project made on codeigniter from internet and edit it.
I downloaded a login form project and tried to read it. But i'm still kind of confused how everything works. i hv 2 questions:
What is the correct approach to learn codeigniter?
In how many days one can learn codeigniter? (i practice around 6-7 hrs a day)
The best way to learn codeigniter is to read the manual of codeigniter
Because, codeigniter framework is so much popular for their well formatted and clean documentation.
Or you can check this for beginner level tutorial
Or if you want to learn codeigniter by doing practical projects then you can follow this link
I learned CI over a weekend using this technique.
Start with simply setting up a 2 page site.
Home and About Us.
Pass simple string variables from the controllers to the views.
Next, bring a model into it.
Make a method in your model that returns some plain text, to the controller and finally to the model.
Next, make the model actually make a request to your database and return the result to the constructor then view.
After that try these:
write a helper function
Try making a basic route
Log a debugging message
upload a file from a form using the upload library
That's a good grounding in CI
Keep in mind Codeigniter is no longer in development also.
If your keen on sticking with PHP, you might want to check out the similar active project called "Laravel" after getting the hang of CIs very simple MVC structure.
Good luck!
the common way is read their manual and follow the guide, the another approach is search youtube for codeigniter turial, there are many good tutorial out there and easy to follow for example here is my result in the first place for keyword "codeigniter tutorial"
https://www.youtube.com/watch?v=BP9NRZXOvIw&list=PLIQyGVrcLTeXsq37O7IBGaUwu6xEwqBWV&index=1

Laravel 4 Blade templates documentation

I'm new to Laravel 4. I don't seem to find adequate documentation on the Blade templating system.
I see some examples at http://laravel.com/docs/templates with no explanation.
Another example at Laravel 4 Controller Templating / Blade - Correct method?
Where are #section, #yield, #show, etc defined and documented? Where is the Blade templating system actually explained?
Or is it so new, or so "intuitive", that it needs no explanation? Or I could use another templating system that is better documented?
I would say Blade is so easy that it doesn’t need documentation.
Follow this link great tutorial by Jeffrey Way which will take you through everything you need to know.
https://tutsplus.com/lesson/templating-changes/
I am totally convinced that the original documentation about has many areas of opportunity. Anyway, Dayle Rees has done an excellent job through the pages of Code Bright. The Blade section of the book has some great examples that perfectly complement the original documentation. I find it strange that wasn't previously mentioned. You should give it a look.
Regards!
The documentation for Blade isn't in the laravel.com docs. No, they tucked it away in their readthedocs.io account:
https://laravel-guide.readthedocs.io/en/latest/blade/

Building an online MVC architecture description

I would like to create for my Yii application, a site where I can describe each model, view and controller used. However, doing this for each and everyone of my classes would be an extremely long task which I believe might already be solved out there.
Is there a way to automatically create an site with each model/view/controller and its methods, so then I can add a description to it?
Have you tried phpDocumentor http://www.phpdoc.org/? It's crawls your PHP files' comments and generates a simple website for them in the spirit of JavaDocs.
Or, better still, there is a custom extension you can use to build docs like those on the Yii site call Yii Docs Generator http://www.yiiframework.com/extension/yiidocsgenerator. See the details at http://www.yiiframework.com/wiki/186/how-to-generate-yii-like-documentation
I would take a look at T4MVC - it uses a T4 template to generate code for each controller / method. Maybe you could utilize it.
Have you looked into the Gii module of yii. Once you create the tables it can produce models and then CRUD (create, update, delete) pages. Excluding the database there would be no programming required. And then you have the full source in a readable and documented form to manipulate and change to suite your needs.
If you wan't something a bit more advanced or custom you could extend Gii and produce some of your own templates
Larry Ullman has a really nice series on Learning the Yii Framework. In part 3 of the series, he walks you through configuring Yii and enabling Gii, a web-based automated code generation tool for Yii. In part 5, he shows you how to use it to generate the code for your models. The whole series is a really nice introduction to Yii, I recommend it.

Getting started with Phil Sturgeon's CodeIgniter Template library

I'm trying to use Phil Sturgeon's CodeIgniter Template library, but I can't get it to change my pages. I read the documentation, followed the steps there,
Download
Copy to application folder
Create a views/layouts/default view
(Auto)load the library
however, it is not clear as to how the template is actually implemented. I thought that loading the view would apply the template everywhere, but it doesn't seem to work that way. I've also read about it in the CodeIgniter Wiki, but it looked too complicated to be the right answer.
How are you supposed to use Phil Sturgeon's Template with your controllers? (or views?) Am I missing something here?
It does not overload the load->view() methods, that would be bad. You need to update your controllers to use the template's syntax and methods in every instance you want to use it:
http://philsturgeon.co.uk/demos/codeigniter-template/user_guide/
You will use $this->template->build() instead of $this->load->view() in most cases, after constructing your template by defining regions, setting titles, etc.
There should have been a user guide included in your download with examples.

ASP.NET - MVC 3: Localization

I am about to implement localization for my MVC3 web application. Googling my way through large amounts of ways to do it, I was left unsure which way to implement this. I found few ways how to do it:
First option I found was to use App_GlobalResources and ViewData and culture select with Map Routing. (Link)
Second was to make a separate Resources folder in my project and structure it like Model and View folders. Then create the resource files in those folders. To use those resource strings would be like using the Viewbag. Then edit the Global.asax to handle culture changing and create a partial view to allow changing cultures. The instructions to do this are very thorough so this might be the best bet.
(Link)
Third was to use DisplayAttribute and resx-files. This one was a bit hazy, I could not find the sort of information so that I could grasp how this actually is implemented and its restrictions. (Link)
Fourth was to create a custom class to handle resources. This seemed pretty fancy and easy to implement and use but no real information was found if it actually worked. (Link)
Then I found a post that warned about using the App_GlobalResouces and App_LocalResources. (Link)
After going through possible ways of doing localization. I could not find a way which was universally approved or accepted. This left me pondering, which of these, or some I didn't find, would be the best way to implement localization in ASP.NET MVC3?
Then I found a post that warned about
using the App_GlobalResouces and
App_LocalResources. (Link)
I found that post extremely useful. The method explained there is very clean. Here is a snippet of my newly created index view using that method:
#using Resources.Index
#{
ViewBag.Title = "Index";
}
<h1>#Index.Title</h1>
I don't think there is a definitive do-it-this-way-or-else method, so going for the cleanest method seems to me like a good deal.
I've come up with an easier way to handle localization where you don't have to use resource files or attributes. It involves custom metadata providers.
MVC3 uses metadata providers to get all text strings. My approach allows you to either use string tables, a database, flat files or any other source to provide the translations. All you need to do is to inherit two interfaces.
Read about it here: http://blog.gauffin.org/2011/09/easy-model-and-validation-localization-in-asp-net-mvc3/
Edit
Everything is now documented at github and there are nuget packages: https://github.com/jgauffin/griffin.mvccontrib

Resources