Register, login routes are not put inside Auth middleware right?

|
praneet81 2019-04-27 18:53:20
Amazing
praneet81 2019-04-27 18:53:22
Thank you bro
2019-04-28 07:10:39
I wanto store data from a form with file upload (*.doc) and store the file name to mydatabase, paperstable create schema as follow:
Schema::create(‘papers’, function (Blueprint $table) {
$table->increments(‘id’);
$table->integer(‘user_id’)->unsigned();
$table->foreign(‘user_id’)->references(‘id’)->on(‘users’)->onDelete(‘cascade’);
$table->text(‘author’);
$table->text(‘institution’);
$table->text(‘paper_title’);
$table->string(‘paper_filename’);
$table->smallInteger(‘status’)->default(0);
$table->dateTime(‘moderated_at’)->nullable();
$table->timestamps();
});
I tried to fill the form and submit the data to my table and I got this error: “Call to a member function store() on null” please help
for more detail I attached my controller script and view blade on image at thetop:
2019-04-28 07:17:50
laravel_discuss-5416.jpg

2019-04-28 07:18:15
Sorry here is my controller and my create view
loveycom 2019-04-28 08:46:09
The error is from line 40 in your controller and it is caused by your form. The error message is clear: you are calling store() on empty file.
loveycom 2019-04-28 08:49:11
That means request->file() is not getting any file. Can you figure out why? It is simple. Just look at your code.

Clue: compare controller line 40 with form line 34.

2019-04-28 10:17:03
loveycom 2019-04-27 18:39:01
The most important lines: 81, 89 and 93.

πŸ‘πŸ‘πŸ‘ great solution with explaination brother!!

StanleyMasinde 2019-04-28 10:26:35
loveycom 2019-04-28 08:49:11
That means request->file() is not getting any file. Can you figure out why? It is simple. Just look at your code.

Clue: compare controller line 40 with form line 34.

If this is so…. the forms enctype needs to be multipart….

loveycom 2019-04-28 10:51:37
2019-04-28 10:17:03
πŸ‘πŸ‘πŸ‘ great solution with explaination brother!!

Thanks so much.

loveycom 2019-04-28 10:52:16
StanleyMasinde 2019-04-28 10:26:35
If this is so…. the forms enctype needs to be multipart….

There’s nothing wrong with that. I have told you the lines to check and correct

StanleyMasinde 2019-04-28 11:05:58
loveycom 2019-04-28 10:52:16
There’s nothing wrong with that. I have told you the lines to check and correct

It’s not my code I was just contributing

loveycom 2019-04-28 11:35:50
StanleyMasinde 2019-04-28 11:05:58
It’s not my code I was just contributing

OK.

2019-04-28 14:17:06
loveycom 2019-04-28 08:49:11
That means request->file() is not getting any file. Can you figure out why? It is simple. Just look at your code.

Clue: compare controller line 40 with form line 34.

My mistakeπŸ˜…. I already fix it, thanks alot for your help

Marvixino 2019-04-28 22:32:50
How I can hide the login page/function once the user logged in?
SkipperStrange 2019-04-28 22:41:04
Add middleware auth:web to your authentication controller
Marvixino 2019-04-28 22:42:15
SkipperStrange 2019-04-28 22:41:04
Add middleware auth:web to your authentication controller

With Vue and api

SkipperStrange 2019-04-28 22:42:57
Api will always return token
SkipperStrange 2019-04-28 22:43:36
Use that in conditional statement on api controller
SkipperStrange 2019-04-28 22:44:02
Or as callback function in api rout
Marvixino 2019-04-28 22:49:07
I added this in app.js
Vue.mixin({
data: function () {
return {
jwt_token: localStorage.getItem(‘access_token’),
status: false
}
},
methods: {
doLogout(){
localStorage.removeItem(‘access_token’)
// this.$router.push(‘/’)
},
isLogged() {
if (this.jwt_token) {
this.status = true
return this.status
}
return this.status
}
}
})
And this in logout.vue
export default {

created() {
console.log(‘THIS LOGOUT PAGE’);
axios.post(url,
axios.defaults.headers.common[‘Authorization’] = ‘Bearer ‘ + this.jwt_token
)
.then(response => {
this.doLogout()
console.log(‘User is logged out’)
})
.catch(error => {
this.doLogout()
console.log(‘User is logged out with errors’)
})
}
}
Working fine, but is the the best way ?

vfd14889 2019-04-29 16:12:22
https://laraveldaily.com/validation-rule-sometimes-apply-rules-only-if-field-exists/

Validation rule “sometimes”: apply rules only if field exists – Laravel DailyLaravel Daily
Recently I’ve found out an interesting validation rule for form fields in Laravel, and I want to briefly tell you about it.
Marvixino 2019-04-29 22:11:43
Any idea how to refresh jwt token by refresh token?
Marvixino 2019-04-29 22:47:47
I need to refresh the jwt token after is expire by the refresh token
Marvixino 2019-04-29 22:54:06
This what I’m trying to do, but getting error 419

public function refreshTokenV2 () {
$http = new GuzzleHttpClient;
$response = $http->post(url(‘oauth/token’), [
‘form_params’ => [
‘grant_type’ => ‘refresh_token’,
‘refresh_token’ => request(‘refresh_token’),
‘client_id’ => ‘2’,
‘client_secret’ => ‘cK13jXYdcIjETs7yKO8wpkvFGoZhN6WgEex9eCbB’,
// ‘scope’ => ”,
],
]);
return json_decode((string) $response->getBody(), true);
}

Marvixino 2019-04-29 22:57:59
Sorry, but what you mean?
Marvixino 2019-04-29 22:58:59
I remove the path ‘oauth/token/refresh’ from CSRF verification, and now the error:

“message”: “Unauthenticated.”

Marvixino 2019-04-29 22:59:34
This without using my custom function
Marvixino 2019-04-29 23:05:05
error 401
Unauthenticated
Marvixino 2019-04-29 23:07:44
Yes, I set the exipre time 1 minute for the token, and 10 minutes for the refresh token. After login with 3 minutes I tried to get new token by the refresh token, but response 401
loveycom 2019-04-29 23:38:42
Marvixino 2019-04-29 23:07:44
Yes, I set the exipre time 1 minute for the token, and 10 minutes for the refresh token. After login with 3 minutes I tried to get new token by the refresh token, but response 401

You passed the refresh route through Auth middleware.

loveycom 2019-04-29 23:39:58
Any route in Auth mw can only be accessed after authentication which you do not have cos your token has expired.
Marvixino 2019-04-29 23:45:52
But auth me needs valid jwt token, is that right?
amirst88 2019-04-29 23:51:31
Hello guys have good nights
Ihave a one question please help me
I will send a 3 photos of codes
Anyone who says the answer
Thanks
amirst88 2019-04-29 23:51:49
laravel_discuss-5463.jpg
Photo from Amir
amirst88 2019-04-29 23:52:10
amirst88 2019-04-29 23:51:49
Photo from Amir

This is error

amirst88 2019-04-29 23:52:37
laravel_discuss-5465.jpg
Photo from Amir
amirst88 2019-04-29 23:52:38
laravel_discuss-5466.jpg
Photo from Amir
amirst88 2019-04-29 23:53:34
amirst88 2019-04-29 23:52:37
Photo from Amir

This is the post model

amirst88 2019-04-29 23:54:06
amirst88 2019-04-29 23:52:38
Photo from Amir

This is the category model

loveycom 2019-04-30 00:01:32
Marvixino 2019-04-29 23:45:52
But auth me needs valid jwt token, is that right?

Yes

Marvixino 2019-04-30 00:02:43
Well, if the me needs valid token how to pass it then?
loveycom 2019-04-30 00:05:20
amirst88 2019-04-29 23:52:37
Photo from Amir

I think you have declared your relationship wrongly. Posts will belong to category, yes but photo will belong to post, not the otherwise way round

loveycom 2019-04-30 00:06:56
Marvixino 2019-04-30 00:02:43
Well, if the me needs valid token how to pass it then?

Register, login routes are not put inside Auth middleware right? Why? Cos as at the time of hitting these routes there is no way to authenticate. So also refresh token.

loveycom 2019-04-30 00:11:10
The api I wrote last week or so, this is how I structure it.

1. Hit the register route with json data for registration, the controller registers you, generate token and return it to user. From here, user do not need to login. Access the secured routes with the token

2. Login with your username and password, and get Token. Use the token to access secure routes.

3. If token expires, you are logged out. Relogin to generates new token.

htoowaikhant 2019-04-30 05:14:35
Hello, i have a problem , service provider not found on productions server. Its work local and test server.
Marvixino 2019-04-30 07:27:22
htoowaikhant 2019-04-30 05:14:35
Hello, i have a problem , service provider not found on productions server. Its work local and test server.

Check the chmod and chown

Marvixino 2019-04-30 07:29:59
loveycom 2019-04-30 00:11:10
The api I wrote last week or so, this is how I structure it.

1. Hit the register route with json data for registration, the controller registers you, generate token and return it to user. From here, user do not need to login. Access the secured routes with the token

2. Login with your username and password, and get Token. Use the token to access secure routes.

3. If token expires, you are logged out. Relogin to generates new token.

But this not a good practice, user always need to login, and jwt should not remain valid for long time

Marvixino 2019-04-30 07:37:27
There is a lot of tutorials bout jwt, but none them of talking about refresh token
htoowaikhant 2019-04-30 08:09:59
Marvixino 2019-04-30 07:27:22
Check the chmod and chown

i already give persmission for 775

|