Category : axios

Routes Route::view(‘/{path?}’, ‘app’); Route::post("users/signup", "[email protected]"); Route::post("users/email/verify", "[email protected]"); Route::get("users/email/resend", "[email protected]"); Verify email once the user clicks on their email <?php namespace AppHttpControllers; use AppMailVerifyEmail; use AppModelsUser; use IlluminateHttpRequest; use IlluminateSupportFacadesMail; class EmailVerificationController extends Controller { public function verify( Request $request){ $user = User::where($request->input("token") ,"verification_token"); if($user){ $user->markEmailAsVerified(); $user->email_verified_at = now(); return response()->json(["msg" => "Email has been verified"]); ..

Read more

I’m having trouble with Vue.js and Axios to fetch pdfs in my Laravel app. When ever a user clicks this button: <a @click="fetchData()"><i class="fas fa-file-download mouse-pointer"></i></a> My fetch method is being called in Vue.js: methods: { fetchData() { axios.get(this.fetchUrl, {responseType: ‘arraybuffer’}) .then(response => { let blob = new Blob([response.data], { type: ‘application/pdf’ }) let link ..

Read more

I’m using Laravel sanctum to use Rest API’s for Laravel Token based authentication and when I send the request to server using axios to the ‘/register’ route it returns a 422 error code . const handleRegister = async (e) => { e.preventDefault() axios.defaults.withCredentials = true axios.get(`${hostName}/sanctum/csrf-cookie`).then((res) => { axios .post(`${hostName}/register`, { name: ‘admin’, email: ‘[email protected]’, ..

Read more

If it’s just formData, I can send it. But if you put other data together, formData will be empty. const formData = new FormData(); formData.append(‘file’, files); axios.post(‘/api/upload’, { formData, route: this.$route.params.test }, { headers: { ‘content-type’: ‘multipart/form-data’, }}).then(response => { console.log(response); }); Is there any way to solve this? Sourc..

Read more

I’m using Laravel and Vue’s component, and when i try to access the banners property from response returned by axios in vue component it gives me undefined. I am accessing the perperty like response.data.banners I’m returning data from controller in following way: public function getBanners(Request $request){ return response()->json([‘ banners’=> BannerImage::active()->get() ]); } Here is how ..

Read more

I’m currently building a single page application based on Laravel and VueJS. Is there any better way then mine to handle errors with axios? This is how I currently do it when a user clicks on login button: VueTemplae: methods : { authenticateUser() { axios.post(‘/api/login’, this.form).then(() => { this.$router.push({name : ‘home’}); }).catch((error) => { this.error ..

Read more

I am using Laravel and Vue. When I was searching on the internet I saw the following code. <script> export default { data() { return { movie: {} } }, methods: { createMovie() { this.axios .post(‘http://localhost:8000/api/movie/create’, this.movie) .then(response => ( this.$router.push({name: ‘movie’}) )) .catch(error => console.log(error)) .finally(() => this.loading = false) } } } I ..

Read more

I’m working with vuejs and want to submit files using axios I try to append files to FormData but it still not working The only thing I know how to do is showing the file’s name <template> <div> <div class="row"> <div class="col-lg-9 col-md-9 col-sm-12"> <div class="form-inline mb-3 pt-3"> <label for="date">Date:</label> <input type="date" name="date" id="date" min=’2020-05-08′ ..

Read more

I started learning Vue.js but i cannot figure this out: I have this function: getTotalUser: function (book_id) { axios.get(‘/total/’ + book_id) .then((response) => { console.log(response.data) return response.data; }) .catch(function (error) { console.log(error) }); } I call the function inside a v-for loop, like this: <tr v-for="(book, index) in books"> <td>{{ getTotalUser(book.id) }}</td> </tr> The function ..

Read more

I have been struggling to get past the CORS error I am receiving. I keep getting in my console this error: Access to XMLHttpRequest at ‘http://localhost:8000/register’ from origin ‘http://localhost:3000’ 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 have added CORS ..

Read more

I am having a problem uploading an image from a from a form in a vue file. I tried several ways to do this but it seems the file is not properly being set. I have set "enctype="multipart/form-data" in my form tag Here is my input element: <input @change="onFileChange" type="file" accept="image/*" class="form-control" name="file" id="file" aria-describedby="helpId" ..

Read more

I have a problem retrieving data from mysql to a table using Axios and Vue Js. I get an error http://localhost:8000/api/allusers 403 (Forbidden). This is my code: UserController <?php namespace AppHttpControllers; use IlluminateHttpRequest; use Appuser; use IlluminateSupportFacadesHash; class UserController extends Controller { public function __construct() { $this->middleware(‘role:user|superadministrator’); } public function index() { return view(‘user.index’); } ..

Read more