cideaz's avatar

Post method shows 404

Hello guys,

Weird problem , could not get it resolved from gitter.im for laravel , So All I am trying to say that I have already researched about it .

Problem

When I try to upload a file using post method from my mobile device to Lumen server it says 404

routes.js

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/

$app->get('/', function () use ($app) {
    return $app->version();
});

$app->get('/token','StockHandler@getToken');

$app->post('/upload','StockHandler@stock_in_out');

Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\File;
class StockHandler extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    public function getToken()
    {
        echo "Hjkl1234-vikram";
    }

    public function stock_in_out()//Request $request
    {

        try{

            $file = Request::file('file');
            Storage::put('batch/'.$file->getClientOriginalName(),  File::get($file));
            return response()->json('success');
            
        }catch(Exception $e)
        {
            echo json_encode(e);
        }
        

    }
   
}

/bootstrap/app.php

<?php

require_once __DIR__.'/../vendor/autoload.php';

try {
    (new Dotenv\Dotenv(__DIR__.'/../'))->load();
} catch (Dotenv\Exception\InvalidPathException $e) {
    //
}


$app = new Laravel\Lumen\Application(
    realpath(__DIR__.'/../')
);


$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class
);

$app->singleton(
    Illuminate\Contracts\Console\Kernel::class,
    App\Console\Kernel::class
);

$app->singleton('filesystem', function ($app) {
    return $app->loadComponent('filesystems', 'Illuminate\Filesystem\FilesystemServiceProvider', 'filesystem');
});

$app->middleware([
    \Barryvdh\Cors\HandleCors::class,
]);


$app->register(Barryvdh\Cors\ServiceProvider::class);

$app->withFacades();

$app->group(['namespace' => 'App\Http\Controllers'], function ($app) {
    require __DIR__.'/../routes/web.php';
});

return $app;
0 likes
0 replies

Please or to participate in this conversation.