Did you write Vue in Laravel or did you it separately?

|
2020-07-11 20:55:41
return $user it has error
isofdev 2020-07-11 21:03:37
2020-07-11 20:54:56
protected function create(array $data)
{

if (request()->hasFile(‘avatar’)) {
$avatarapload = request()->file(‘avatar’);
$avatarname = time() . ‘.’ . $avatarapload->getClientOriginalExtension();
$avatarpath = public_path() . ‘/images’;
$avatarapload->move($avatarpath, $avatarname);
$user= User::create([
‘name’ => $data[‘name’],
‘lastname’ => $data[‘lastname’],
’email’ => $data[’email’],
// ‘avatar’=> $avatarname,
‘avatar’ => !empty($avatarname) ? $avatarname : ‘download.png’,
‘password’ => Hash::make($data[‘password’]),

]);
}
return $user;

Replace request() by $data

2020-07-11 21:06:26
I don’t have with upload but it gives an error to the last return
isofdev 2020-07-11 21:14:42
2020-07-11 21:06:26
I don’t have with upload but it gives an error to the last return

Where is the end of your if?

2020-07-11 21:15:01
isofdev 2020-07-11 21:14:42
Where is the end of your if?

return $user;

2020-07-11 21:16:17
I want to save the default photo, return does not accept the last one
isofdev 2020-07-11 21:17:03
2020-07-11 21:15:01
return $user;

The if must end before
$usee = User:: Create

harmlez_prinz 2020-07-12 09:56:30
2020-07-11 20:54:56
protected function create(array $data)
{

if (request()->hasFile(‘avatar’)) {
$avatarapload = request()->file(‘avatar’);
$avatarname = time() . ‘.’ . $avatarapload->getClientOriginalExtension();
$avatarpath = public_path() . ‘/images’;
$avatarapload->move($avatarpath, $avatarname);
$user= User::create([
‘name’ => $data[‘name’],
‘lastname’ => $data[‘lastname’],
’email’ => $data[’email’],
// ‘avatar’=> $avatarname,
‘avatar’ => !empty($avatarname) ? $avatarname : ‘download.png’,
‘password’ => Hash::make($data[‘password’]),

]);
}
return $user;

What is the error u getting?

YOUCODEWORLD 2020-07-12 11:29:28
2020-07-11 20:54:56
protected function create(array $data)
{

if (request()->hasFile(‘avatar’)) {
$avatarapload = request()->file(‘avatar’);
$avatarname = time() . ‘.’ . $avatarapload->getClientOriginalExtension();
$avatarpath = public_path() . ‘/images’;
$avatarapload->move($avatarpath, $avatarname);
$user= User::create([
‘name’ => $data[‘name’],
‘lastname’ => $data[‘lastname’],
’email’ => $data[’email’],
// ‘avatar’=> $avatarname,
‘avatar’ => !empty($avatarname) ? $avatarname : ‘download.png’,
‘password’ => Hash::make($data[‘password’]),

]);
}
return $user;

the if steatment NOT working so return not undefind $user

YOUCODEWORLD 2020-07-12 11:30:37
you try give default value to $user
harmlez_prinz 2020-07-12 12:02:22
Please who is Familia with Laravel vue here i need help
harmlez_prinz 2020-07-12 12:03:21
any idea please, this is new for t

“Access to XMLHttpRequest at ‘http://localhost/api/auth/register’ from origin ‘http://127.0.0.1:8000’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.”

YOUCODEWORLD 2020-07-12 12:08:45
harmlez_prinz 2020-07-12 12:03:21
any idea please, this is new for t

“Access to XMLHttpRequest at ‘http://localhost/api/auth/register’ from origin ‘http://127.0.0.1:8000’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.”

you install laravel-cors

harmlez_prinz 2020-07-12 12:09:35
YOUCODEWORLD 2020-07-12 12:08:45
you install laravel-cors

Installed

harmlez_prinz 2020-07-12 12:09:55
It is just not working
YOUCODEWORLD 2020-07-12 12:09:57
take a picture
harmlez_prinz 2020-07-12 12:10:35
YOUCODEWORLD 2020-07-12 12:09:57
take a picture

Which section of my code?

YOUCODEWORLD 2020-07-12 12:10:49
you must allow http://localhost the sever header
harmlez_prinz 2020-07-12 12:11:39
YOUCODEWORLD 2020-07-12 12:10:49
you must allow http://localhost the sever header

How do i go about this please

YOUCODEWORLD 2020-07-12 12:11:50
yarn add vue-axios-cors
YOUCODEWORLD 2020-07-12 12:12:19
import AxiosPlugin from ‘vue-axios-cors’;

Vue.use(AxiosPlugin)

YOUCODEWORLD 2020-07-12 12:13:00
app.all(‘/*’, function(req, res, next) {
// CORS headers
res.header(“Access-Control-Allow-Origin”, “*”); // restrict it to the required domain
res.header(‘Access-Control-Allow-Methods’, ‘GET,PUT,POST,DELETE,OPTIONS’);
// Set custom headers for CORS
res.header(‘Access-Control-Allow-Headers’, ‘Content-type,Accept,X-Access-Token,X-Key’);
if (req.method == ‘OPTIONS’) {
res.status(200).end();
} else {
next();
}
});
YOUCODEWORLD 2020-07-12 12:13:55
https://github.com/christiannwamba/scotch-vue-store

christiannwamba/scotch-vue-storeGitHub
Contribute to christiannwamba/scotch-vue-store development by creating an account on GitHub.
YOUCODEWORLD 2020-07-12 12:14:13
this code include cors
YOUCODEWORLD 2020-07-12 12:14:27
https://scotch.io/courses/build-an-online-shop-with-vue/enabling-cors

Enabling CORSScotch
CORS stands for Cross-Origin Resource Sharing, and it’s tricky. Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources (e.g. fonts) on a web page to be requested from another domain outside the domain from which the first resource was served. – Wi
harmlez_prinz 2020-07-12 12:14:59
YOUCODEWORLD 2020-07-12 12:14:27
https://scotch.io/courses/build-an-online-shop-with-vue/enabling-cors

Thanks, let me check the solution out

YOUCODEWORLD 2020-07-12 12:15:04
but you can install you app
Blue Sky, [12 Jul 2020 at 5:11:50 PM]:
yarn add vue-axios-cors

import AxiosPlugin from ‘vue-axios-cors’;

Vue.use(AxiosPlugin)

harmlez_prinz 2020-07-12 12:15:44
YOUCODEWORLD 2020-07-12 12:14:27
https://scotch.io/courses/build-an-online-shop-with-vue/enabling-cors

Am not using node

I am using laravel

YOUCODEWORLD 2020-07-12 12:16:48
。。。
YOUCODEWORLD 2020-07-12 12:17:01
You using Vue also
harmlez_prinz 2020-07-12 12:17:14
YOUCODEWORLD 2020-07-12 12:17:01
You using Vue also

Yes

YOUCODEWORLD 2020-07-12 12:17:24
and you have a two server
harmlez_prinz 2020-07-12 12:17:31
YOUCODEWORLD 2020-07-12 12:14:27
https://scotch.io/courses/build-an-online-shop-with-vue/enabling-cors

This tutorial is for node js

YOUCODEWORLD 2020-07-12 12:17:34
Laravel already install cors
harmlez_prinz 2020-07-12 12:17:42
YOUCODEWORLD 2020-07-12 12:17:24
and you have a two server

Yes i do

YOUCODEWORLD 2020-07-12 12:17:49
but vue not.
harmlez_prinz 2020-07-12 12:17:53
YOUCODEWORLD 2020-07-12 12:17:34
Laravel already install cors

Yes….

YOUCODEWORLD 2020-07-12 12:18:36
You are a front and backend is separate right?
harmlez_prinz 2020-07-12 12:19:34
YOUCODEWORLD 2020-07-12 12:18:36
You are a front and backend is separate right?

Yes they are

Using vue for front and laravel for backend

YOUCODEWORLD 2020-07-12 12:19:58
So you allow two side
YOUCODEWORLD 2020-07-12 12:20:18
Only backend can’t working
harmlez_prinz 2020-07-12 12:22:15
Okay. Let me work on that
Josjess 2020-07-12 12:22:44
laravel_discuss-44722.jpg

harmlez_prinz 2020-07-12 12:50:14
YOUCODEWORLD 2020-07-12 12:12:19
import AxiosPlugin from ‘vue-axios-cors’;

Vue.use(AxiosPlugin)

Still same thing mate

YOUCODEWORLD 2020-07-12 12:50:59
Did you write Vue in Laravel or did you it separately?
YOUCODEWORLD 2020-07-12 12:51:42
“Access to XMLHttpRequest at ‘http://localhost/api/auth/register’ from origin ‘http://127.0.0.1:8000’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.”
YOUCODEWORLD 2020-07-12 12:51:55
http://localhost/ this is a Laravel server right ?
YOUCODEWORLD 2020-07-12 12:52:44
harmlez_prinz 2020-07-12 12:50:14
Still same thing mate

which one is Laravel server?

harmlez_prinz 2020-07-12 12:54:16
YOUCODEWORLD 2020-07-12 12:51:42
“Access to XMLHttpRequest at ‘http://localhost/api/auth/register’ from origin ‘http://127.0.0.1:8000’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.”

I don’t get

harmlez_prinz 2020-07-12 12:54:33
I started the app with php artisan serve
|