I have conditions in blade and working fine but little bit worry if somebody comes and use inspect element so he can add href and link and make button as example working if it was disabled, so what is the good way to secure my code
#if (auth()->user()->customer->package_id>0)
<li class="btn_disabled"> Allready Purchased</li>
#elseif(auth()->user()->customer->package_id==null)
<li class="buttonprice">Purchase</li>
#endif
Related
Hi and I'm terribly sorry for asking such question.
I'm quite catching up on Laravel, maybe 30% smarter than before but I'm stuck on this kind of scenario.
How do I call a blade with all parameters passed to its controller without refreshing the page.
Here's my folder structure (I will not place all just controller, pages)
Folrder Structure
Now, I'm in let's say dashboard.blade.php
In the Side bar of my dashboard I want to go to a link
<li class="nav-item">
<a href="{{url('/get-greeting/{id}/{user}')}}" class="nav-link get-greeting">
<i class="nav-icon fas fa-table"></i>
<p>
Requested Son
<span class="right badge badge-danger side-span requested-span"></span>
</p>
</a>
</li>
Route will be
Route::any('/get-greeting/{id}/{user}', 'DefaultController#pullGreeting')->name('getgreeting');
Controller will be
public function pullGreeting($id, $user){
$userName = User::activeUser($user);
$defaultarray = array( 'greetingLogs' => recordLogs::pullgreetings($user) );
return view('pages/department1/greetings',$defaultarray);
}
When I click it, it refreshes the page. Anyone, can you help me and pinpoint where am I doing wrong so I can make it not refreshing the page but instead changing the blade dynamically?
Does this matter?
return view('pages/department1/greetings',$defaultarray);
or
return view('pages.department1.greetings',$defaultarray);
PHP is a server-side programming language therefore any changes to the view will require a full page refresh.
Without the use of Javascript, achieving a part page refresh would require the use of an old school technique called Frames.
You could redesign your application to render HTML via different endpoints and have a Javascript powered frontend that calls to those endpoints.
You could easily achieve through the use of JS Libraries such as React or JQuery.
Hi all i will be needing an assistance. I have a navbar that all link on my app use but i will like to seclude a search form from some of the link in the app but am having difficulty doing that. This what i have tried on my nabvar so far example
Tried using route but no success
#if( (route('portfolio') &&(route('portfolio.details)
content here
#else
content
#endif
then i tried targeting the URI
#if( Request::is('/portfolio') &&(route('portfolio/details)
content here
#else
content
#endif
None seems to working.
I don't think you should be using the route helper method in your if statement. I think if you just do something like this, it should work.
#if (request()->is('portfolio'))
content
#else
content
#endif
I want to show in my view one section if conditional is true, other section if it is false. I am using PhpStorm as IDE and what I get in those cases is that directive is not closed:
#if (conditional)
#section('content')
...
#stop
#else
#include('pages.something')
#endif
I am getting that opening #if is not closed, and that #else is missing opening directive.
Front-end works fine, but this is really bugging me in IDE. Can it be resolved?
EDIT:
This only happens when using conditionals and sections together. Conditionals and includes work fine.
Try to wrap your content using #yield
See laravel's docs for reference. https://laravel.com/docs/5.5/blade#template-inheritance
I had read somewhere the the Laravel helper functions route() and url() would match the protocol of the current page. This has not been my experience and I cannot find a way to do it cleanly.
<!-- https://domain.com/public/route1 -->
<a href='{{ route('route2') }}'> domain.com/route2 </a>
404 due to lack of "/public/" and no https
<a href='{{ url('/route2') }}'> domain.com/public/route2 </a>
proper path but still drops https
<a href='{{ secure_url('/route2') }}> https://domain.com/public/route2 </a>
proper path and protocol but is explicit
Is there a way to do what I want? It seems absurd to me that these helpers would be unable to accomplish something this simple. Something that the following line of code does with no tricks (its downside being the obvious loss of benefits associated with using helper functions [UPDATE: in particular having everything break when running locally due to a different app path]):
<a href='/public/route2'> https://domain.com/public/route2 </a>
To further convolute things I would like to add that when running on localhost, the first version {{ route('route2') }} produces a path that includes /public/, though it is possible that I have a different config file somewhere on the server (this is a very large project). Bonus points if someone can point me in the right direction for that issue as well.
routes.php:
Route::group(array('prefix' => 'route2' ), function(){
Route::get('/', array(
'as' => 'route2',
function(){
return View::make('pages.route2');
}
));
...
});
Thank you kind souls!
UPDATE:
I have continued searching and been unable to find any relevant information regarding Helper function url generation. It seems the majority of info with similar keywords is about forcing HTTPS site-wide (server config) or setting up redirects. It just seems so much simpler to generate the correct link in the first place. Plain HTML can do it, so should Laravel.
UPDATE 2:
Using the asset helper seems to work how I would expect url to. Please someone tell me this hack is not my only option...
I am currently generating my application urls using {{action('Namespace\Class#method')}}. How would I check if the current page request maps to that current action Namespace\Class#method?
I would like to do something like:
<a href="{{action('Namespace\Class#method')}}
#if (currentAction('Namespace\Class#method'))
class="active"
#endif
>Some link</a>
How would I achieve this in Laravel 5?
There's no built in method for this, however you can retrieve the current action name with Route::currentRouteAction(). Unfortunately this method will return a fully namespaced class name. So you will get something like:
App\Http\Controllers\FooBarController#method
You can either check for that or use something like ends_with so you don't have to specify the full path:
#if(ends_with(Route::currentRouteAction(), 'FooBarController#method'))
You might also consider naming your routes with 'as' => 'route.name'. This would allow you to use: Route::is('route.name')
Actualy I had it simplified to the following code:
<li class="#if(Route::is('getLogin')) active #endif">Login</li>
That assumes that you have named routes. Which is a good idea in the first place, because you migth change the url of an action without going through your whole project to change the links to that action.
I know this is old, but for what it is worth.
Laravel has a couple of built-in helper methods for referring to URLs action and route.
action
Your route file would look like this.
Route::get('/funtastic', 'FuntasticController#show');
Your blade view would look like this
<a href="{{action('FuntasticController#show')}}
#if(action('FuntasticController#show') == Request::url())
class="active"
#endif
>Some link</a>
route
If you use named routes.
<a href="{{route('namedRoute')}}
#if(route('namedRoute') == Request::url())
class="active"
#endif
>Some link</a>
This is how I do it without any named routes
<a class="{{ str_contains(request()->url(), '/some-page') ? 'active' : '' }}" href="/some-page">Some Page</a>
This is not a perfect solution but it works for most cases
It works perfectly for me.
<a class="#if (\Route::current()->getName() == 'device_media') active #endif" href="{{ route('device_media', ['brand_slug'=>$brand->slug, 'slug'=>$device->slug]) }}" > Media</a>