how to set remember me option in laravel 5.4 using cookie - php

in controller
$cookie=Cookie('rem_username',$username,60);
$cookie1=Cookie('rem_password',$password,60);
return redirect()->action("Logincheck#dashboardvalue")->cookie($cookie)->cookie($cookie1);
the cookies are set ,
how to use this in view page of login

You can use Cookie facade or use cookie helper function
{{ Cookie::get('rem_username') }} OR
{{ cookie('rem_username') }}

May this also work for you:
{{\Illuminate\Support\Facades\Cookie::get('rem_username')}}

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]

How to access cookie from view in PHP Laravel 5

I can access cookie in controller then pass it to view
//HomeController.php
public function index(Request $request)
{
$name = Cookie::get('name');
return view('index', ['name'=> $name]);
}
But I want to write a small control (widget) that can fetch data from cookie without concern of parent controller. For example, header, footer widgets could fetch its own data without main page controller knowing which data is needed.
I can query the data from database by using View Composer. But, how can I access data from view in the request cookie ?
Using static function with defining namespace and etc is a not safe.
Cuz maybe in next versions of framework this namespace can change.
It's better to use helper functions.
{{ request()->cookie('laravel_session') }}
or
{{ cookie('laravel_session') }}
Tested on working app with Laravel 5.2
You can use {{ Cookie::get('laravel_session') }} to print out the cookie inside your view.
You can use
{{\Illuminate\Support\Facades\Cookie::get('laravel_session')}}
in a blade template
You can use:
$response = new \Illuminate\Http\Response(view('your_view'));
$response->withCookie(cookie('cookieName' , 'cookieValue' , expire));
return $response;
or
\Cookie::queue('cookieName', 'cookieValue', expire);
return view('your_view');
I've used both of them.

Go back URL in Laravel 5.1

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() }}

Lumen: get URL parameter in a Blade view

I'm trying to get a url parameter from a view file.
I have this url:
http://locahost:8000/example?a=10
and a view file named example.blade.php.
From the controller I can get the parameter a with $request->input('a').
Is there a way to get such parameter from the view (without having to pass it from the controller to the view)?
This works well:
{{ app('request')->input('a') }}
Where a is the url parameter.
See more here: http://blog.netgloo.com/2015/07/17/lumen-getting-current-url-parameter-within-a-blade-view/
The shortest way i have used
{{ Request::get('a') }}
Given your URL:
http://locahost:8000/example?a=10
The best way that I have found to get the value for 'a' and display it on the page is to use the following:
{{ request()->get('a') }}
However, if you want to use it within an if statement, you could use:
#if( request()->get('a') )
<script>console.log('hello')</script>
#endif
More simple in Laravel 5.7 and 5.8
{{ Request()->parameter }}
Laravel 5.8
{{ request()->a }}
This works fine for me:
{{ app('request')->input('a') }}
Ex: to get pagination param on blade view:
{{ app('request')->input('page') }}
You can publicly expose Input facade via an alias in config/app.php:
'aliases' => [
...
'Input' => Illuminate\Support\Facades\Input::class,
]
And access url $_GET parameter values using the facade directly inside Blade view/template:
{{ Input::get('a') }}
As per official 5.8 docs:
The request() function returns the current request instance or obtains an input item:
$request = request();
$value = request('key', $default);
Docs
All the answers above are correct, but there's a quickier way to do this.
{{request("a")}}
Laravel 5.6:
{{ Request::query('parameter') }}
As per official documentation 8.x
We use the helper request
The request function returns the current request instance or obtains
an input field's value from the current request:
$request = request();
$value = request('key', $default);
the value of request is an array you can simply retrieve your input using the input key as follow
$id = request()->id; //for http://locahost:8000/example?id=10
if you use route and pass paramater use this code in your blade file
{{dd(request()->route()->parameters)}}
here is the code to get filtered data with pagination
$queryvariable->appends($data)->links('link of new page');
note there
$data = $request->all();

Using Settings::get('var_name') in Laravel template instead of Config::get('file.var')

I would like to store my application settings in database.
In order to get a variable in template, I'm currently using
{{ Config::get('file.variable) }}
and settings are stored in config/file
I would like to create controller SettingsController with public static get and set methods and get variables in template in this way:
{{ Settings::get('var_name') }}
instead of
{{ SettingsController::get('var_name') }}
But I'm getting error: Class 'Settings' not found.
I've tried to set routes:
Route::controller('Settings', 'SettingsController'); and
Route::resource('Settings', 'SettingsController');
But none of the methods works.
Any ideas how to solve this problem?
This should be done using facades, which is already answered here:
How to create custom Facade in Laravel 4

Categories