Category : rest

I’m trying to work with an API that already given me a TOKEN and I have added this TOKEN at Authorization section as BearerToken and then added this GET request (which requires no parameter): https://seller.digikala.com/api/v1/profile/ But after sending it, I get the Status 401 Unathorized somehow. So what’s going wrong here? How can I properly ..

Read more

I am preparing a common and current CRUD-type REST API with the users model that laravel brings by default <?php namespace AppModels; use LaravelSanctumHasApiTokens; use IlluminateNotificationsNotifiable; use IlluminateContractsAuthMustVerifyEmail; use IlluminateDatabaseEloquentFactoriesHasFactory; use IlluminateFoundationAuthUser as Authenticatable; use IlluminateAuthPasswordsCanResetPassword; class User extends Authenticatable implements MustVerifyEmail { use HasApiTokens, HasFactory, Notifiable, CanResetPassword; /** * The attributes that are mass ..

Read more

I have the following API endpoints: Route::post(‘/jobs’, [JobController::class, ‘store’]); Route::patch(‘/jobs/{id}’, [JobController::class, ‘update’]); Route::delete(‘/jobs/{id}’, [JobController::class, ‘destroy’]); Should I add the following redundanct endpoints? Redundant in the sense that they point to the same controller functions. Route::post(‘/projects/{projectId}/jobs’, [JobController::class, ‘store’]); Route::patch(‘/projects/{projectId}/jobs/{id}’, [JobController::class, ‘update’]); Route::delete(‘/projects/{projectId}/jobs/{id}’, [JobController::class, ‘destroy’]); I personally find specifying resources as top-level resources rather than nested resources ..

Read more

I have this very simple form in postscreate.blade.php <form action="http://example.com/posts" method="POST"> @csrf <input type="text" name="title"> <input type="submit" value="SUBMIT"> </form> and this route in web.php Route::resource(‘posts’,’PostController’); When I enter some text in the text input field named title and submit the form, it submits to the correct method [email protected] since a POST request to http://example.com/events leads ..

Read more

Fiddling with Laravel and coming from Symfony, I’m trying to replicate some code. I’m trying to PUT a Suggestion model (overwritting anything, even relationships) and wanted to know the proper way to overwrite the model. Since tags attribute in fillable doesn’t exist, I certainly get an error (Undefined column: 7 ERROR: column "tags" of relation ..

Read more

I have a RESTful laravel 8 application where I store videos in the storage. To return a video file in my Controller I have the following code which returns the video: $file = Storage::get($videoName); $type = Storage::mimeType($videoName); $videoSize = filesize(storage_path($videoName)); return response($file, 200)->header(‘Content-Type’, $type)->header(‘Content-Length’, $videoSize); JavaScript is used for the frontend. When I have several ..

Read more

My computer is accidentally blue screen, and shutdown automatically. So, I turn on it again, and then I open my project built with Laravel and Vue.js. But, suddenly it show me 431 (Request Header Fields Too Large). What’s wrong? It’s very strange. Before this accident, the API request is normal. Now, it can’t be accessed ..

Read more

when i run php artisan route:list i can find the route GET|HEAD | accounting/sales but whenever i send the request using postman i get the same error SymfonyComponentHttpKernelExceptionMethodNotAllowedHttpException: The GET method is not supported for this route. Supported methods: POST. in file C:xampphtdocsprojectscontrollercontrollerapivendorlaravelframeworksrcIlluminateRoutingAbstractRouteCollection.php on line 117 and when i try to to change the request ..

Read more

BadMethodCallException Method AppHttpControllersOrderController::rajaOngkirRequest does not exist. IlluminateRoutingController::__call C:xampphtdocslaravel7-larashop-feature-E.10-rest-api-product-cataloguevendorlaravelframeworksrcIlluminateRoutingController.php:68 <?php namespace IlluminateRouting; use BadMethodCallException; abstract class Controller { /** * The middleware registered on the controller. * * @var array */ protected $middleware = []; /** * Register middleware on the controller. * * @param Closure|array|string $middleware * @param array $options * @return IlluminateRoutingControllerMiddlewareOptions */ public ..

Read more

I have an api for fetching some data from DB and I need to write another function to give Json API for user registration in my ApiController. How can I do this ? this is my ApiController <?php namespace AppHttpControllers; use IlluminateHttpRequest; use AppModelsTerms; use IlluminateSupportFacadesDB; class ApiController extends Controller { public function getTerms(string $id){ ..

Read more

I am creating authorization in SPA, On the server – Laravel + sanctum On the client – Vue + Axios I want to make protection against CSRF, for this I installed the Sanctum package in app/Http/Kernel.php file added Middleware ‘api’ => [ EnsureFrontendRequestsAreStateful::class, ‘throttle:api’, IlluminateRoutingMiddlewareSubstituteBindings::class, ], in routes/api.php file created route Route::post (‘/register’, [AuthController::class, ‘register’]); ..

Read more