I'm running some tests on building an API with Laravel. All the URLs of the API are currently accessing without authentication. I am trying to allow after user authentication.
In routes / api.php I'm defining:
<?php
use Illuminate\Http\Request;
Auth::routes();
Route::get('/member/{id}', 'PessoaController@edit')->middleware('auth:api');
And in my controller is defined this way:
<?php
namespace App\Http\Controllers;
use App\Pessoa;
use JsValidator;
use Illuminate\Support\Facades\Validator;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Requests\PessoaRequest;
date_default_timezone_set('America/Sao_Paulo');
class PessoaController extends Controller
{
public function __construct(Pessoa $pessoa)
{
$this->Pessoa = $pessoa;
$this->middleware('auth.api')->except(['index', 'show']);
$this->middleware('auth.api:optional')->only(['index', 'show']);
}
}