Go back URL in Laravel 5.1 - php

How can I get the previous URL visited on the website in Laravel 5.1?
In Laravel 4 I just needed to write it like below:
{{ URL::previous() }}

The cleanest way seems to be using the url() helper:
{{ url()->previous() }}
URL::previous() works for me in my Laravel 5.1 project. Here is Laravel 5.1 doc for previous() method, which is accessible through URL Facade.
You can still try alternatives, in your views you can do:
{{ redirect()->getUrlGenerator()->previous() }}
or:
{{ redirect()->back()->getTargetUrl() }}

Related

Redirect with parameters Lumen

I want to make redirect with parameters in Lumen (as laravel).
For example. It working in laravel
laravel:
return redirect()->route("main")->with("success", "Success!");
Blade:
<h4 class="text-center" >{{ session('success') }} </h4>
In lumen doesn't exists "with()" but i know that via headers can do it
In advance thanks for help.
Lumen dropped session support in past few versions.
If you want, you can use Laravel session package or simply manually set PHP session ex: $_SESSION['success']['Success!'] and then retrieve it {{ $_SESSION['success'] }}.
Answer for Laravel session package [https://stackoverflow.com/a/47055083/9851907]

Laravel blade "{{ command }}" not working correctly

I have this weird problem with my Laravel 5.5 version... I created the auth views using
php artisan make:auth
This command created the views controllers and everything I need to lets get stared to work. But I'm having this visualization problem
As you can see on the register view I have this problem.
The real thing is that "{{ any_command }}" is printing the code that its supose to generate instead of interprating like part of the code. But if I use {!! any_command !!} instead it seems to work propertly. What can happend to my laravel is screwed up. It has nothing to be with the artisan auth method, because I tried to create a new form (using laravel collective form helper) and get the same result.
{{ }} will escape all data before printing. So, if you write any HTML tag inside, it will be escaped and printed as is. Just like your example.
{!! !!} will print unescaped data. This will print the tags correctly, but you have to take care where you use it, because someone could inject unwanted data there.
So, in your case, you should use {!! !!}.
Please, refer to this question: What is the difference between {{ }} and {!! !!} in laravel blade files?

Laravel 5 GET inside controller?

I use Laravel5 and i cant understand why postProcess or getProcess not works?
Example::
html page:
{{ Form::open(array('url' => 'portfolio/process')) }}
{{ Form::submit() }}
{{ Form::close() }}
route:
Route::resource('portfolio','PortfolioController');
controller:
public function postProcess (){
return 'Text!';
}
Every time i get error:
MethodNotAllowedHttpException in RouteCollection.php line 218:
It doesn't work because Route::resource doesn't build these routes and you need to explicitly define them:
Route::post('portfolio/process', 'PortfolioController#postProcess');
I think you need to check your route list:
Run this command php artisan route:list in terminal and check your route.
Hope this work for you!

Laravel 5: Class 'HTML' not found

I'm just getting started with Laravel. I'm in a controller method and I say:
return \View::make('scrape', $data);
Then in scrape.blade.php I have:
#extends('layouts.master');
Finally, in layouts/master.blade.php I have:
{{ HTML::style('css/bootstrap.min.css') }}
And that where things seem to fall apart and I get:
FatalErrorException in 002eb18bb71fd3ec1de058967b799d49 line 6:
Class 'HTML' not found
What am I doing wrong? Thanks for your help.
Searching on google I found this
"By default in Laravel 5.0, Html and Form are not embedded anymore."
You need to add this package to you application.
Please use above links and last change HTML to Html.
eg:
{{ HTML::style('css/bootstrap.min.css') }}
to
{{ Html::style('css/bootstrap.min.css') }}.
its working.

Class 'Sentinel' not found (Laravel 4)

I'm using Laravel 4 and rydurham/Sentinel (https://cartalyst.com/manual/sentinel). I'm able to log in users, register users and display the Sentinel views I've customized perfectly fine. The config changes I've made register fine. However, when I include:
{{ Sentinel::check() }}
or
{{ Sentinel::guest() }}
I get the error Class 'Sentinel' not found. I notice there is no Sentinel Facade in $aliases, and running composer dump-autoload does not fix this. Any thoughts?
The problem was that I'm using rydurham/Sentinel and not Cartalyst's Sentinel package. They are two different things. rydurham/Sentinel includes the facades for Sentry though, so you can use:
{{ Sentry::check() }}
{{ Sentry::guest() }}

Categories