URL::assets Laravel 5.2.29 - laravel-5

I want to call all my css and js files using UR::asset
but the problem is it returns this output "Method does not exist."
My code:
<link href="{{ URL::asset('public/css/style.css') }}">

You just need to use public_path() method for this.
i.e
public_path('css/style.css');
Here is laravel documentation link

Just make sure you don't have any typos in your code: URL::asset(). I would also suggest using the helper function asset() instead for brevity.

Related

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

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'];

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

Laravel Collective Syntax

I'm learning laravel (5.5) from a book.
I installed laravel collective, the book says, to link a css file write like this:
{{!! HTML::style('css/app.css') !!}} It works fine.
but in the output two empty {} braces appear (because they are not being used as part of the syntax). So, I removed them and it still works fine.
Question is which syntax is correct?
this {{!! HTML::style('css/app.css') !!}}
or {!! HTML::style('css/app.css') !!}
???
Out of the box Laravel tries to help you with security within your apps. When outputting data using the {{ $foo }} data, Laravel automatically calls the htmlspecialchars() method to prevent XSS attacks. In some cases you do want or need to output HTML, that's why Laravel created a separated syntax for that: {!! $foo !!}.
So to answer your question: {!! $foo !!} is the correct syntax.
Off topic:
If you'd like to not use the unescaped data syntax, you could write you're CSS linking like this:
<link rel="stylesheet" href="{{ asset('css/app.css') }}">

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.

Resources