I have a Laravel Application with some Angular JS, I'm using Laravel to do the routing as it's easier for my team (who rarely use JS at all) to understand later, I have a route that allows me to create briefings, this is done first by selecting some options (which are passed as an array to the Laravel Controller and sent to the view) and then generating the project
Now, when I have the project generated I'm taken to another view with a sidebar, this sidebar allows me to change to different subsections of the briefing, for instance, there's a section for Development and another for Design.
These are different routes in Laravel that take the user to different forms, the problem is that these forms need to generate conditionally with blade's #if command and in order to do that, I need to get the original options array from my generator view into all of these other views.
How can this be achieved in Laravel 5.2?
Did you try to use SESSION ?
On submit a form, use SESSION to save some data that you need and you can easily find it at any moment with SESSION.
Related
I am building a survey questionnaire in PHP using Laravel and there are five HTML pages (one for each section). Do I need to create separate controllers for each HTML page in order to process the data to the database?
Usually it is good to stick to the different logic-different controller.
As you provided very small amount of info, its not clear what you want to do, but based on the info I understand, you’ll just need one controller and one method for all the html pages.
So I'm using laravel 5.1 and I'm stuck in a weird situation.
I have 2 models Seasonand Tournament and lets say the url to add a Season model is ..../seasons/add and to view the season would be ..../seasons/(id)... standard stuff right?
But now I want to add a tournament from the link ..../seasons/1 and so I click a link that takes me to ..../tournaments/add... how can I send the Season model to that page without submitting a form with hidden input?
Currently I have this setup ..../seasons/1/tournaments/add using blade to generate the links. But this method just doesn't feel right....
Thanks.
How can I send data from one page to another using Laravel?: I would suggest that you do this from your controller. Take a look at Redirecting With Flashed Session Data, it might come in handy.
From the Flash Data documentation: "[...] it will only be available during the subsequent HTTP request, and then will be deleted [...]"
You can send your model, static values or whatever you want using ->with:
redirect('route')->with('key', 'value');
I think I understand the concept of HMVC after reading this question and answer https://softwareengineering.stackexchange.com/questions/220480/hmvc-and-database-connections; an extract from an answer is below:
Let's assume you want to have a view that enables a user to make a
comment to a blog post. You would have fields for name, e-mail, title
and comment, but you also want to have a field country displayed as a
dropdown. In the action that displays this view you would make a
database query that loads the countries and then populate that
dropdown. Which is ok, but it forces you to duplicate the query and
the view required to display the countries if you need it in another
part of your application. A better approach would be to create
separate controller for countries with an action that returns a view
with the dropdown and then render that action whenever you need to
show a list of countries.
What I cannot wrap my head around is that if I can internally request a controller/model/view which just displays a widget (e.g. a country select box), doesn't that mean that by accessing that url from a browser will also just show that view?
How is this managed in HMVC, are routes defined as internal/external only, so matching an internal route with an external request would show a 404 page?
Is this generally how it is done and is the HMVC description/definition above satisfiable with the general use case of it in most web applications?
Showing the output of a sub-request in the browser shouldn't be a problem, so I wouldn't bother, especially that those URLs are not known by the user and it's safe to output the widgets separately.
Despite the above, you could, as #deceze mentionned, not attach those controllers to any routes. If you have a "default" route (matching all requests), then you would have to disable it.
I am wondering if there are any way in laravel to send a variable to the layout master and keep it there while the user is logged in. I know how I can do it, like this
$this->layout->with('catalog.categories', $data);
But the problem of this is that I will have to be sending the variable on all the controllers and through all the class. And to get the variable I will need seven or eight lines of code on top of that.
I will give you an easy example. Imagine I have a messenger center in my web. And I want to show the user all the messages he did not read on the top bar. It has to be on the layout master and stay there until he read the messages. Do I have to pass this variable every single time the user changes the route?
Laravel has a nice way to handle issues where a same data is used in all views. View Composer is what you are looking for.
View::composer(array('view1','view2'), function($view)
{
$view->with('data', 'value');
});
Now data varaible is bound to view1 and view2. That means they it will be available every time you load these views.
Where to place them? You can place your view composers wherever you want as long as Laravel can identify it.
Read docs: View Composer
I started creating own Symfony bundles some weeks ago. I've created some entities with all the stuff around (also used the Doctrine CRUD-command), made some twig extensions and created new templates.
Now I wanted to implement a Search Form in my Project. Are there some simlpe ways or some predefined Search-Bundles, which I can use in my Project?
I created my search-form manually (form without an entity). Then form is submitted via GET and the Results (selcted from the Entities in the Controller with a repository-search) are shown below the search form on the same page.
Now I think, that it isn't good to have a very long URL, because of the Fields in the Form. I could go further and submit e.g. a <select> list with multiple entries selected and the URL would even be longer.
Would it be a good choice to submit the Form via POST, "cut" the unnecessary "URL-Array-Elements" (+make the Query-Items more readable for humans) and redirect to the URL with the queries for showing the results?
Edited: Are there any simple ways, how I can create a specific search form or entity-filter which I can use for custom entities? I like to use/create a function, where I can insert the entity, define the search-tags/filters and output a search-form? Has anyone created/used such search/filter-functions?