Category : laravel-api

I am using Dynamic database for my laravel API Project. I am doing that with a middleware. When I use auth:sanctum in api rout middleware not working. But normally its working fine. Route> api.php Route::group([‘middleware’=>’database’], function() { Route::group([‘namespace’ => ‘AppHttpControllersAdmin’, ‘middleware’ => [‘auth:sanctum’]], function () { Route::get(‘dashboard’, function () { return "conncted sucessfully to database ..

Read more

I made a flutter program to download pdf files from laravel. I get an error when I press the download button. Exception has occurred. HandshakeException (HandshakeException: Handshake error in client (OS Error: CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:354))) Here is my download function : Future<File> _downloadFile() async{ final res = await Network().download("/letter/download/${surat.id_surat}"); var bytes ..

Read more

How to use laravel JsonResource to generate json response for a polymorphic relationship. Consider below example use IlluminateDatabaseEloquentRelationsMorphTo; $activities = ActivityFeed::query() ->with([‘parentable’ => function (MorphTo $morphTo) { $morphTo->morphWith([ Event::class => [‘calendar’], Photo::class => [‘tags’], Post::class => [‘author’], ]); }])->get(); return ActivityResource::collection($activities); The parent of the activity feed can be anything Ex: Event, Photo, Post etc. ..

Read more

I don’t really understand why but whenever I reach this point on my code, the result is blank/empty on Postman //check if user exists based on email $userExistanceCheck = $this->findUser($userResponse[’email’]); if ($userExistanceCheck->getData()->status == 400) { //begin user registration. He doesn’t exist return $this->createUser($userDataArray); }else if($userExistanceCheck->getData()->status == 200){ return $this->responser(‘user found’,$userExistanceCheck->getData(),200); <—Here } If I do ..

Read more

I have API which I have uploaded on the server. The url looks like this: api.subdomain.domain.com/ I’ve made .htaccess to go directly to the public but when accessing it should be like this: api.subdomain.domain.com/api/login How can I access it directly like api.subdomain.domain.com/login. This is my .htaccess RewriteEngine On RewriteCond %{HTTPS} !on RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] ..

Read more

i want to create a new user and generate password grant token inside a db transaction like this : $createdUser= DB::transaction(function () use ($request) { $createdUser=$this->userService->create($request->validated()[‘user’]); $accessToken=$this->userService->generateUserToken($request->validated()[’email’], $request->validated()[‘password’]); }); the generateUserToken function send the /OAuth/token to get a new token but passport send MySQL query to select the created user which is not in DB ..

Read more

Environment Laravel Version: 8.27 PHP Version $ php –version: PHP 8.0.3 (cli) Database Driver & Version $ mysql –version: mysql Ver 8.0.23-0ubuntu0.20.04.1 Problem Statement Getting Blank Body while accessing Laravel API from Postman with correct Header (i.e. Accept: application/json) and Bearer Token for Authorization even though Status is 200 I even tried entering wrong Token ..

Read more

Environment Laravel Version: 8.27 PHP Version $ php –version: PHP 8.0.3 (cli) Database Driver & Version $ mysql –version: mysql Ver 8.0.23-0ubuntu0.20.04.1 Problem Statement Getting Blank Body while accessing Laravel API from Postman with correct Header (i.e. Accept: application/json) and Bearer Token for Authorization even though Status is 200 I even tried entering wrong Token ..

Read more

<?php namespace AppHttpResources; use IlluminateHttpResourcesJsonResourceCollection; class LanguageCollection extends ResourceCollection { public $collects = LanguageResource::class; /** * TagCollection constructor. * @param $resource */ public function __construct($resource) { parent::__construct($resource); } /** * Transform the resource collection into an array. * * @param IlluminateHttpRequest $request * @return array */ public function toArray($request) { return [ ‘languages’ => parent::toArray($request) ..

Read more

I am developing a file system management using laravel 8. I created a function that accept file. public function uploadExperiment(Request $request) { $file = $request->file(‘file’); $uniqueId = time(); $fileName = $file->getClientOriginalName(); $filePath = $uniqueId . ‘/’ . $fileName; Storage::disk(‘local’)->put($filePath, file_get_contents($file)); return response()->json(["success"=>true]); } I need to track the uploaded size during the uploading process and ..

Read more

I use sanctum for my vue Axios operations. I deploy to my shared hosting and I get this error in the chrome console: GET http://foo.xyz/city 401 (Unauthorized) bootstrap.js : window._ = require(‘lodash’); try { window.Popper = require(‘popper.js’).default; window.$ = window.jQuery = require(‘jquery’); require(‘bootstrap’); } catch (e) {} window.axios.defaults.withCredentials = true; window.axios = require(‘axios’); window.axios.defaults.headers.common[‘X-Requested-With’] = ..

Read more