Category : laravel-api

I’m building an API to support an external application. I have added several routes to it with no problem, but suddenly, when I add a new route (acars/delay), I get a 404 error when trying to hit http://myurl.dev/api/acars/delay with a POST request. Here is my api.php file: Route::post(‘acars/deactivate’, ‘[email protected]’); Route::post(‘acars/ofp’, ‘[email protected]’); Route::post(‘acars/create’, ‘[email protected]’); Route::post(‘acars/pirep’, ‘[email protected]’); ..

Read more

I need to connect vuetify v-data-table with laravel api resource. backend : api.php : Route::apiResource(‘category’, CategoryController::class); CategoryController: public function index(Request $request) { return CategoryResource::collection( Category::where("user_id", "=", $request->user()->id) ->orderBy(‘updated_at’, ‘desc’) ->paginate(5) ); } fron-tend Ho in category vuex module: async all({ commit }) { commit("SET_LOADING", true); categoryApi.all().then((response) => { commit("SET_CATEGORIES", response.data["data"]); commit("SET_TOTAL", response.data["meta"]["total"]); commit("SET_LOADING", false); }); ..

Read more

I have very complex functions in laravel APIs ( called from Mobile App). The sample function is given below. If someone can help to improve the code structure. I wish to know the best practices in handling multiple transactions in a single API. Because if I move each table’s entry to separate function – how ..

Read more

I have created two apis one for college students and one for normal users. Normal users api is working fine but college api is not working properly. Can anyone help me fixing this error. What changes should I do ? Controller Codes for both are given below : Routes for both api Route::get(‘/get-user-enrollments/{offset?}’,’[email protected]’); Route::get(‘/get-college-enrollments/{offset?}’,’[email protected]’); Subject ..

Read more

Is it possible to return a image created on the fly with Laravel API Resources without saving it? Tried in controller $sum = Product::where(‘slug’, $product)->first(); $img = Image::make(‘image_path’)->resize(400, 400); $img->text(name, 205, 138, function($font) { $font->file(‘fonts/BostonHeavy.woff’); $font->size(42); $font->color(‘#ffffff’); $font->align(‘center’); $font->valign(‘top’); }); return (new ProductResource($sum))->foo($img); Laravel API Resource <?php namespace AppHttpResources; use IlluminateHttpResourcesJsonJsonResource; class ProductResource extends JsonResource ..

Read more

I asked to create a page that displays a list of all the categories and the last 3 products for each category. There is a relationship between the category and the products. I am trying to generate a route that will return a Json response. Here is my code: $category = Category::all()->load(["products"=>function($res){ $res->take(3); }]); return ..

Read more

Hi I am creating a web app using create-react-app which consumes endpoints developed in laravel 5. When I make a Delete request using axios to the server, I get this error Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:8000/api/carts/7?api_token=r31blLEFtjvA8Zhhba3K1AD083Yj1NUz8U7nUZZsX24EpW9dmtQ3mnOc4DdV. (Reason: Did not find method in CORS header ‘Access-Control-Allow-Methods’) Whereas, ..

Read more

I want to use finerworks api and my curl code is here $data1 = array( ‘web_api_key’ => ‘********-****-****-*****-************’, ‘app_key’ => ‘********-****-****-*****-************’, ); $data2[‘credentials’] = $data1; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://api.finerworks.com/v3/test_my_credentials", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30000, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => json_encode($data2), CURLOPT_HTTPHEADER ..

Read more

I started with Laravel 7 a few weeks ago. It happened to me multiple times that after reading about a topic on the Laravel website, I wanted to check the details of a function, for example: IlluminateSupportFacadesRoute::group() So I went to the Laravel API, and could find the Route facade, but not the group function. ..

Read more

I am trying to get comment and it’s replies in laravel api,I tried following way and faced to this error, how can I solve it? this is my controller: public function postSinglePage(Request $request) { $post_id=$request->get(‘post_id’); $post = Post::where(‘id’,$post_id)->where(‘status’, ‘=’, 1)->get(); return response([ "posts" => GetPostsSinglePageData::collection($post), ]); } and this is my resource collection to get ..

Read more

Thank you in advance, I have one controller function like public function storeBlog(Request $request) { // Here i am receiving file like $request->file(‘image’); } Now I want to send that file to an API endpoint like Http::post(‘http://example.com/v1/blog/store’, $request->all()); I am getting all the request but not file, I know we need to pass POST data ..

Read more

#1: { "id": 1, "is_valid": 1, "name": "Bach Mai", "password_hash": null, "created": null, "updated": null, "interviews": [ { "id": 1, "is_valid": 1, "name": "covid-19", "interview_type": null, "created": null, "updated": null, "interview_questions_count": 6, "pivot": { "hospital_id": 1, "interview_id": 1 }] } #2: { "id": 1, "is_valid": 1, "name": "covid-19", "interview_type": null, "created": null, "updated": null, "interview_questions_count": ..

Read more

I have my code below that checks "if the email has already taken" public function test(Request $request) { $request->validate([ ’email’ => ‘required|email|exists:contacts,email’ ]); // … return response()->json([‘done!’], 200); } When I tried this in Postman, I intentionally send invalid email. But the Postman returned an error. Error: Exceeded maxRedirects. Probably stuck in a redirect loop ..

Read more

I have worked on Paypal Payment Gateway Integration Projects in Laravel project. I mostly used Paypal/Paypal-php-sdk package. Here But I came to know about srmklive/laravel-paypal package which looks more easier. Here. I think above two payment Apis are working slightly different. First of all, I took api keys from different places in Paypal account. In ..

Read more