How do I get url parameter in Blade template (Laravel v8) - laravel

As the title suggests, I am resurrecting an old Laravel project (from v5) and upgrading to v8.
In my blade template I referred to $request->q which would get the q=somevalue part of my url, in laravel 8 however this doesn't work.
I have tried a number of methods found in this SO post but none of them work.

Have you tried request() helper function with one of these
request('q')
request()->get('q')
request()->query('q')

I had this issue too but Still, it will works, when it in this way
Controller
in here this should have use Illuminate\Http\Request;
public function func1(Request $request){
$aid=$request->id;
}
Route
Route::get('/url_name/{id}',[
'as'=>'url_name',
'uses'=>'ControllerName#func1'
]);
Blade
<form id="form_1" action="{{'/url_name',$id)}}" method="POST" enctype="multipart/form-data">
OR
You can try with,
$request['q'];

Related

Stripe Payment Integration problem In Laravel . When I submit form its say given below

The POST method is not supported for this route. Supported methods: GET, HEAD.
The stripe form here I use the post method
<form action="{{ route('paid') }}" method="POST">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_51Gx4RHGN82mlZ9FRpFQJX53WYhxxiNUDyANdIU7JTBOp2VE9UqCU7Me2YLu0pGdbhmFCfhBU670F9cTdzcKVH6s200EvaEy45p"
data-amount="999"
data-name="Stripe.com"
data-description="Widget"
data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
data-locale="auto"
data-zip-code="true">
</script>
</form>
And the route is given below
Route::post('/paid', 'PublicController#paid')->name('paid');
And controller
public function paid(Request $request)
{
dd($request->all());
}
I use post method but it always says
The POST method is not supported for this route. Supported methods: GET, HEAD.
how can I solve it? I am so tired to solve this. please help me, anyone
Thanks
Laravel has an inbuilt function called Laravel Cashier, you should use this instead of coding it through your method as it will be far simpler:
https://laravel.com/docs/7.x/billing
If you want to fast track it even further you can use this which will give you some initial dashboards to work with:
https://github.com/jeremykenedy/laravel-cashier-examples
I hope that helps

Vue varibale inside Laravel helper

This is my Laravel route:
Route::get('/article/{id}', 'ArticleController#show')->name('article');
This is my blade in Laravel:
Article
I tried this:
How to place vue variable inside a laravel bracket
But for me this return:
https://example.xyz/article/%7B%7B%20value.id%20%7D%7D
I need something like that:
Article
Where article.id is a Vue variable.
How can I do this?
You can't do it this way. But you can use Ziggy which allows you to use route() function in vue like you are using it in laravel.
https://github.com/tightenco/ziggy
Then in your vue component you can call route('article', {id: article.id})
You can try this
Article

Using route() and with() in html view in Laravel 5.6

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

Laravel creates new CSRF token on each refresh

I'm using Laravel version 5.2.37. I have a simple HTML form in the blade view with the following line:
<input type="hidden" name="_token" id="token" value="{{ csrf_token() }}">
When I upload the code to client's shared hosting (Cpanel, PHP 5.5.36), without submitting the form, I hit the refresh and the csrf token value keeps changing.
However, on my local machine (MacOS/Apache2/5.6.16), the csrf token persists for at least 2 minutes (per config/session.php settings). Could it be the older 5.5.36 version of PHP that's causing this?
Try to define 'domain' in config/session.php to the right path. By default, it's set to null but on server, you should clear that.
Well, I finally figured it out. Stupid me made a custom helper with a function that looked something like this:
<?php
function doSomething($arg)
{
?><p>When this function is called,
display <b><?php echo $arg; ?> value.</b></p>
<?php
}
?>
You've probably seen a lot of functions written like this inside WordPress. Although it's not the artisan code, in most cases it will work fine, however Laravel will not tolerate this type of nonsense when dealing with helpers. So everything came back to normal after I wrote my function to return the string instead:
<?php
function doSomething($arg)
{
return '<p>When this function is invoked,
display <b>' . $arg . '</b> value.</p>';
}
?>
Moral of the story - don't write ugly code. Make sure your function returns and never directly echos/prints strings, especially with helper functions.

Laravel 4.1 Blade + Handlerbar escaping issue (%20, %7B etc ..)

I'm working with Laravel 4.1 (recently update to) and Handlebars.
I have a view where I mix Blade template and Handlebars template.
My problem is that this line:
View
return me this :
http://local/event/%7B%7Bid%7D%7D
instate of :
http://local/event/7 (if id = 7)
Note that this line return the correct value :
<span>#{{id}}</span>
The issue occurs only in the url() Laravel helper :(
Thank you in advance!
You cant get Handlebars to put the $id there - because it is a Laravel PHP function url() that must resolve first, and the result is passed to Handlebars.
i.e. this would work:
View
But you cant get Handlebars to use an ID in the Laravel function.
What you are trying to do in your example is get Laravel to pass a URL to Handlebars, Handlebars inserts the ID, then Laravel finishes the function - which wont work.
In my case the workaround is
View

Resources