Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have two controllers:
AdminController
ProductController
AdminController has some functions:
index
create
etc
ProductController also has some functions:
index
create
etc
In admin dashboard there is a button Product. When I will click it it will call ProductController index page.
Then in Product button subsection create, edit, delete etc will be available.
at last my url will be: admin/product/create
How is this possible? Give me idea.
Have a look at Routing Prefixes. This way, the admin slug is always there but you can bind the rest of the actions from there. Furthermore, you can have multiple prefixes within each other if you'd like. If you are not familiar with the routes.php, I'd suggest reading through the documentation and just simply play with it a bit.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am trying to get values from database in an anchor tag, but it's not working. My code is :
<a href="{{url('admin/$getStudyLevel->slug_name/$getStudyLevel->id')}}" class="small-box-
footer">Get In <i class="fas fa-arrow-circle-right"></i></a>
Thanks
There are few way to pass param to url .Suppose consider you have following route
Route::any("user/{id}/{email}",[UserController::class,'index'])->name("userDetail");
then in your view using route name you can pass
User Detail
if you are using url then
User Detail
or
User Detail
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I was wondering of what could be the advantages or disadvantages of using slug instead of id when looking for a model or for urls.
Because there is a possibility to bind directly the url so that in the web.php file, this url /users/{user} will become the following:
with id:
domain.com/users/1
or with slug:
domain.com/users/IQii33XAQhldEK
Thanks
IQii33XAQhldEK is not a slug, a slug would be domain.com/users/patrissol-kenfack.
In the case of the slug, the 2 benefits are:
Better readability for humans,
Better for SEO, because Google will see the keywords in the URL.
If you use id in the url, it could mean that users would be able to know what the id of the resource they are viewing are. Usually, this won't be much of an issue, but if proper security practices are not followed, users could modify resources using this id by passing it implicitly (So make sure to use $fillable or $guarded) . For example, a malicious user could simply put a
<input type="text" name="id" value="<the-id-of-any-other-resource>"
And if you insert or update models with $request->all(), it could end up modifying the id of that resource.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I am making a website using laravel. I have a search page where users can search for products and a SearchController which does the actual searching.
Right now, I am passing the form data to the controller with a post method (search string, filters, etc.), it works brilliantly!
However, I see that almost every website passes the search parameters in the URI using a query string. Why is tht better? Should I be doing the same?
Thanks!
It's good to keep query parameters in uri for SEO purpose. If you use post method, when you refresh page you won't get data. If you use get method, even page is refreshed you will get data. If you pass query in uri, you can directly get the data by accessing that url.
The search parameter in URL is helpful when the user wants to search more item related to that without refreshing the page. You can do it by ajax and php.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am new to Magento. I just want to know in which situation we write the code in Block directory? Why we cannt write same code in Controllers?
I read articles for this but does not get the answer.
Thanks in advance.
Take a look # Magento for Developers: Part 4 - Magento Layouts, Blocks and Templates
Unlike many popular MVC systems, Magento's Action Controller does not
pass a data object to the view or set properties on the view object
(with a few exceptions). Instead, the View component directly
references system models to get the information it needs for display.
One consequence of this design decision is that the View has been
separated into Blocks and Templates. Blocks are PHP objects, Templates
are "raw" PHP files (with a .phtml extension) that contain a mix of
HTML and PHP (where PHP is used as a templating language). Each Block
is tied to a single Template file. Inside a phtml file, PHP's $this
keyword will contain a reference to the Template's Block object
We write the code in Block directory for creating blocks.
Example: we need to show a block at the left sidebar. controller doesn't need for this.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I´m starting to developing with cake php. I have designed a DB model and baked my mvc´s.
Now i want a index / home site. This site should be an overview of possible actions which a user can do.
Should I use an app_controller for that or route to an existing controller even if that controller has nothing to do with a home site, or should I use a separate controller with no model just for displaying the overview and edit the route of / to point at this new Home Controller?
Whats the best practice for that?
Your question is a little vague to me. I am going to assume that by "site" you mean "page".
If by "overview of possible actions which a user can do" you mean a static page with links, then use the provided PagesController, and create a view at app/views/pages/home.ctp.
If by "overview of possible actions which a user can do" you mean a dynamic page with links and data, then create a controller action to feed the page the correct data.
Where that controller action goes should depend on where the data comes from.
If it lists the latest posts, create a PostsController::home() action.
If it needs data from the User model in order to determine what to display, then create a UsersController::home() action.
Finally, if you are mixing data from many models with no clear winner, or you are actually creating a home "site" instead of a "page", create a HomeController or DashboardController.
Read this post by teknoid for a nice succinct way of loading in arbitrary models when needed.