laravel-5.2

Auth::user() returns null in Laravel 5.2

 ̄綄美尐妖づ 提交于 2019-11-30 23:46:59
I have searched and found various results like these: auth()->user() is null in Laravel 5.2 and Auth::user() returns null But, mine is still not working. Auth::user() works in the controller, but not in the Model. It returns null . The code is: public function scopeOwned($query) { $query->where('user_id', '=', Auth::user()->id); } I tried dd(Auth::user()) and it returns null as well. Any Idea? Thank you guys. The problem solved here: https://laracasts.com/discuss/channels/laravel/authuser-returns-null-in-laravel-52 I had to add the stack into middleware directly (not in the group). in /Http

Session data not preserved after redirection

别来无恙 提交于 2019-11-30 23:17:36
问题 I'm trying to implement some custom flash messages and I'm having some issues with the session data being destroyed after a redirect. Here's how I create my flash messages : flash('Your topic has been created.'); Here's the declaration of the flash() function : function flash($message, $title = 'Info', $type = 'info') { session()->flash('flash', [ 'message' => $message, 'title' => $title, 'type' => $type, ]); } And here is how I'm checking the session/displaying the flash messages, using

Laravel customized session.lifetime at user level

 ̄綄美尐妖づ 提交于 2019-11-30 21:04:53
I am overwriting session.timeout value in one of the middleware (for Laravel web app) but it doesn't seem to be affecting in terms of timing out a session. Though if I debug it shows value I have overwritten. Config::set('session.lifetime', 1440); default value is as following: 'lifetime' => 15, Website that I am working on has very short session lifetime for most of the users but for selected users I want to provide extended session lifetime. It seems the only way to accomplish a dynamic lifetime value, is by setting the value in middleware, before the session gets initiated. Otherwise its

Laravel 5.2 login session not persisting

最后都变了- 提交于 2019-11-30 18:42:26
I have been implementing a simple authentication system on Laravel 5.2 using Sentinel . // Route : /login $success = Sentinel::authenticate(array( 'email' => $email, 'password' => $password, )); echo $success ? 'Login success' : 'Login failed'; So, the above code outputs Login success after the authentication code. But, the login status is not getting persisted to other requests. ie: if I check the authentication status from other requests, it is saying that I am not logged in! // Route : test-login echo \Sentinel::check() ? 'User is logged in' : 'User is not logged in'; I have even tried to

Auth::user() returns null in Laravel 5.2

感情迁移 提交于 2019-11-30 18:05:53
问题 I have searched and found various results like these: auth()->user() is null in Laravel 5.2 and Auth::user() returns null But, mine is still not working. Auth::user() works in the controller, but not in the Model. It returns null . The code is: public function scopeOwned($query) { $query->where('user_id', '=', Auth::user()->id); } I tried dd(Auth::user()) and it returns null as well. Any Idea? 回答1: Thank you guys. The problem solved here: https://laracasts.com/discuss/channels/laravel

Laravel customized session.lifetime at user level

倖福魔咒の 提交于 2019-11-30 15:50:16
问题 I am overwriting session.timeout value in one of the middleware (for Laravel web app) but it doesn't seem to be affecting in terms of timing out a session. Though if I debug it shows value I have overwritten. Config::set('session.lifetime', 1440); default value is as following: 'lifetime' => 15, Website that I am working on has very short session lifetime for most of the users but for selected users I want to provide extended session lifetime. 回答1: It seems the only way to accomplish a

Laravel secure Amazon s3 bucket files

青春壹個敷衍的年華 提交于 2019-11-30 15:47:46
问题 I am using Amazon s3 but here i am facing two problems 1.I cant directly upload files to amazon server when i submit form.I mean i have to upload images to upload folder and from there i have to retrieve and upload to s3 server .is there a way to upload images directly when we click on submit ? 2.if i pass 'public' in s3 put object then only i can access or view files but if i make it public every one can view files but i need to protect all files and view only to the authenticated user .Can

Laravel 5.2 Service provider not booting

…衆ロ難τιáo~ 提交于 2019-11-30 12:35:14
I have a weird issue with a service provider. I have a ComposerServiceProvider with a dd("I'm loaded"); in the boot() function. Nothing is happening. I also have App\Providers\ComposerServiceProvider::class in config/app.php. I ran composer dump-autoload several times. Can anybody help? <?php namespace App\Providers; use Illuminate\Support\ServiceProvider; class ComposerServiceProvider extends ServiceProvider { /** * Bootstrap the application services. * * @return void */ public function boot() { dd("I'm loaded"); } /** * Register the application services. * * @return void */ public function

what is the difference between X-XSRF-TOKEN and X-CSRF-TOKEN?

陌路散爱 提交于 2019-11-30 11:59:49
When use hidden field and when use header and why ? X-XSRF_TOKEN when we use? X-CSRF TOKEN when we use? when you are submitting your data using ajax you will need headers for CSRF token because ajax will not send the token along with the data. You can use hidden field for ajax request with following code $.ajaxSetup( { headers: { 'X-CSRF-Token': $('input[name="_token"]').val() } }); but you will have to add hidden field for every ajax requests. The difference between the X-CSRF-TOKEN and X-XSRF-TOKEN is that the first uses a plain text value and the latter uses an encrypted value, because

Laravel 5.2: Unable to locate factory with name [default]

我的梦境 提交于 2019-11-30 11:10:41
I want to seed database when I use this public function run() { $users = factory(app\User::class, 3)->create(); } Add three user in database but when I use this public function run() { $Comment= factory(app\Comment::class, 3)->create(); } Show me error [InvalidArgumentException] Unable to locate factory with name [default] [app\Comment]. By default the laravel installation comes with this code in the database/factories/ModelFactory.php File. $factory->define(App\User::class, function (Faker\Generator $faker) { return [ 'name' => $faker->name, 'email' => $faker->email, 'password' => bcrypt(str