For redirection, in controllers, we can write like this:-
Redirect::Route('front_index')->with('RegError', 'An error occured while adding the user.');
How can I set up the href of an anchor tag so that I can send the 'RegError' too? Say something like this?
<a href="{{route('front_index')->with('RegError', '')}}">
actually you can't because with function is used to pass parameters from controllers to view and route helper doesn't have this method.
You need to make request and in controller pass your RegError
Related
Am trying to use two different functions from one controller in a single page route
Route::get('/cart','App\Http\Controllers\Frontend\CartController#index');
Route::get('/cart','App\Http\Controllers\Frontend\CartController#alldata');
But the problem is the function alldata works where the function index doesn't
You can't have 2 GET routes with the same path.
Route::get('/cart','App\Http\Controllers\Frontend\CartController#index');
Route::get('/cart/all','App\Http\Controllers\Frontend\CartController#alldata');
The /cart route is overwritten by the alldata(). So the alldata() is calling instead of index().
kindly remove the alldata()'s route and pass the data from index().
Route::get('/cart','App\Http\Controllers\Frontend\CartController#index');
Route::get('/cart','App\Http\Controllers\Frontend\CartController#alldata');
Try to manipulate your logic in controller rather than in route file.
Use conditional in controller function.
I would like to create an url as shown below
/domain/url=cloud_hosting&name=cloud_hosting
this is the href url that I use in my blade
continue
but that href url is generating different route
/domain/cloud_hosting/cloud_hosting
I have tried this one:
Continue
and that's working fine. But is there any other way which is nice and beautifull?
Thank you
you can do something like below. simply make a get request as in Web.php
Route::get('domain')
and can use it like below and can pass multiple query strings:
continue
You can also use the query method:
url('domain', Arr::query(['url' => request()->segment(2), 'name' => $page_name]))
// /domain/url=cloud_hosting&name=cloud_hosting
I'm using Laravel with a Vue component called vue-good-table. I just want to pass an array from my component to one of my Laravel routes and consequently to the respective controller.
I tried with axios but in this case it doesn't work, because the controller that receives the data must return straight away a Laravel view (but using axios the view is returned to the Vue component method as a response).
Maybe I can try to use a button that calls the route but I'm having trouble passing the array I need to pass. The route I specified must use the GET method.
MyTable.vue
<a :href="/pdf-download-selected/">
<button>Download PDF</button>
</a>
I really don't understand if my approach to Laravel with Vue is completely wrong or what..I mean I know how to pass data from Laravel to Vue, but not the opposite.
What do you recommend I do?
Thanks!
I use $.getJSON() to retrieve some data for a couple of cascading dropdowns in my form. $.getJSON() automatically appends the parameter at the end of the URL like domain.com/controller/method/?parent=5
So, I've declared my method like public function method($parent) which works file, but the same method will be used from other parts of the website that will call it like domain.com/controller/method/5
I tried to create a route in routes.php like the one below:
$route['business/regions/?parent=(:num)'] = 'business/regions/$1';
but it doesn't seem to work. Am I doing something wrong? Maybe ? is confusing the regex parser of the router? Do I have to escape it somehow to make it a 'literal' ? ?
Or is it that router is not used to 'rewrite' get parameters at all? I'm very confused, as it should work but it doesn't and I'm wondering what's wrong with it...
Codeigniter route parameters are for url parameters. It is particularly useful when trying to create a REST styled url pattern.
What you're trying to do is get url query string from the url which is not supported via the Codeigniter router. For you to get what you want you can do the following:
In your routes.php:
$route['business/regions'] = 'business/regions';
and in your controller Business.php:
public function regions() {
//the numeric id you're looking for
$parent = $this->input->get('parent');
}
In my view I create links via:
URL::action('NotSureWhatController#getIndex', 'id') }}
My view is a template that is used by a variety of different controllers, what's the best way to change the name of the controller in the action?
The only thing I can think of is setting a var in the controller and passing it through.
Is there a better way? Or a way to get the controller name?
I can't use 'as' in the route to name the controller either (as this is used for something else) so this won't work:
Route::currentRouteName()
Option 1
You should create the URL directly in the controller, then pass it as a variable to the view. The view will just print the url.
Option 2
You pass the name of the controller as a variable to the view (always from the controller), then you use the escape values of the blade templating to print it inside your function to generate URLs.
Option 3
Using the REQUEST class to get information about the page.