0

Hello guys I am new to Laravel and I recently competed my rest Api which is working fine when I tested on local host it is giving me output when i uploaded this rest Api on hostinger it gives me issues like put and post request working as get request I am testing my Api on Postman and I don't know What to do

I followed this tutorial

https://youtu.be/57Ej3X6tzfw

and i use this video for uploading project on hostinger

https://youtu.be/gchU8sPLtXI

I was expecting all things work but post and put request not working.

This is my controller

    public function store(Request $request){
         $validator = Validator::make($request->all(),[
            'name' => 'required|string|max:191',
'course' => 'required|string|max:191',
            'phone_no' => 'required|digits:10',
            'email' => 'required|string|max:191',
            
         ]);

This is my model class

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class UserModel extends Model
{
    use HasFactory;

    protected $table = 'users';

    protected $fillable = [
        'name',
        'course',
        'email',
        'phone',
    ];

    // protected $primarykey = "id";

    
}

This is my route

Route::get('student', [UserController::class, 'index']);
Route::post('student', [UserController::class, 'store']);
Route::get('student/{id}', [UserController::class, 'show']);
Route::get('student/{id}/edit', [UserController::class, 'edit']);
Route::put('student/{id}/edit', [UserController::class, 'update']);

What is happening when I try to post request through postman I am getting datas like get request no error is showing

Bolow is example it's not belong to my code but i shown the example and it's not same as mine data

I except this result on pust request

enter image description here But I am getting this result on post request enter image description here

I followed this toturial https://youtu.be/57Ej3X6tzfw

It's working fine in my computer on local host but when I uploaded on hostinger the post and put request acting like get

  • can you edit your question and add the error you see, what you did, etc. Also change your title to be as specific as possible – Mr. Kenneth Aug 08 '23 at 04:01
  • i am not getting any error i getting response like get request but post should only post the request hope you understand my problem – Suraj Kumar Aug 08 '23 at 04:11
  • No I do not. This would be easier if you can provide some code that you think is the problem. – Mr. Kenneth Aug 08 '23 at 04:35
  • I have added the code section please help me out – Suraj Kumar Aug 08 '23 at 06:17
  • can you post the exact error message ? – Mr. Kenneth Aug 08 '23 at 06:21
  • What was the code you used to execute POST? – Mr. Kenneth Aug 08 '23 at 06:22
  • Based on the controller that you want to execute and the current route. You may be trying to submit http request (GET OR POST) on the same route `/user`. If so, you can try this SO answer https://stackoverflow.com/a/28583318. – Mr. Kenneth Aug 08 '23 at 06:35
  • However this only works if you are using the same `controller@method`. If you want to use different `controller@method` you can change the route `/user` in either get or post method. then change the used route in your frontend – Mr. Kenneth Aug 08 '23 at 06:36
  • I have updated the post please check it – Suraj Kumar Aug 08 '23 at 06:57
  • You are trying to submit POST request to `/api/students` but the route you gave is for `/user?` How will we know what is the relation on user and student? Please review your question again and `ADD` or `REMOVE` parts that is needed or not needed. – Mr. Kenneth Aug 08 '23 at 07:00
  • Please check the I have updated the whole code – Suraj Kumar Aug 08 '23 at 07:12
  • I'm not getting error – Suraj Kumar Aug 08 '23 at 07:17
  • Did you try this https://stackoverflow.com/a/28583318/13933721 ? Like I posted earlier? – Mr. Kenneth Aug 08 '23 at 07:19
  • Was there anything you even tried to do? did you check logs ? your controller is not even complete. Only validation. – Mr. Kenneth Aug 08 '23 at 07:20
  • I have tried to change the route and function name but this not work I am getting any error it's showing data but neither the validation failed nor error shown not success message not shown only data is showing I don't know what went know on hostinger – Suraj Kumar Aug 08 '23 at 07:24
  • Did you `Log` one by one in your controller? So that you can see which part is giving error. Did you check that you are executing the correct controller ? – Mr. Kenneth Aug 08 '23 at 07:27
  • It's working well means everything thing is working fine on local machine while testing when I put it on hostinger it's not working how can I check log there ? Guide me – Suraj Kumar Aug 08 '23 at 07:30
  • This will take too much time for me to just 'guide' you. You need to learn how to debug this first. Like I said, use `Log` in your controller to log texts in your app (Local and Server). Look for tutorials on how to log. Can't do everything for you. This might be controller issue or server issue (if this is only happening in hostinger) – Mr. Kenneth Aug 08 '23 at 08:36
  • Ok once I learn I let you know about this thanks for your advice could you suggest me articles or YouTube video regarding this topic – Suraj Kumar Aug 08 '23 at 08:56
  • Logging: https://laravel.com/docs/10.x/logging#log-levels – Mr. Kenneth Aug 08 '23 at 08:57
  • Try to search where is the log file when you using laravel logging – Mr. Kenneth Aug 08 '23 at 08:58
  • It was silly mistake I was not adding https:// on post man that's why I'm getting the error – Suraj Kumar Aug 16 '23 at 09:54

0 Answers0