Where is the end of your if?
What is the error u getting?
Which section of my code?
You are a front and backend is separate right?
Did you write Vue in Laravel or did you it separately?
which one is Laravel server?
{
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
Where is the end of your if?
return $user;
The if must end before
$usee = User:: Create
{
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?
{
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
“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.”
“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
Installed
Which section of my code?
How do i go about this please
Vue.use(AxiosPlugin)
// 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();
}
});
Contribute to christiannwamba/scotch-vue-store development by creating an account on GitHub.
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
Thanks, let me check the solution out
Blue Sky, [12 Jul 2020 at 5:11:50 PM]:
yarn add vue-axios-cors
import AxiosPlugin from ‘vue-axios-cors’;
Vue.use(AxiosPlugin)
Am not using node
I am using laravel
Yes
This tutorial is for node js
Yes i do
Yes….
Yes they are
Using vue for front and laravel for backend

Vue.use(AxiosPlugin)
Still same thing mate
which one is Laravel server?
I don’t get