我有一个问题,我无法在Laravel 5.4中解决。 我正在使用Postman扩展来请求我的API,到目前为止它通常与GET一起工作,但是当我尝试执行POST时,实际调用的方法再次是GET。 (API不能为用户提供身份验证或令牌)。
api.php:
<?php
use Illuminate\Http\Request;
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
Route::group(['api' => ['auth:api']], function(){
Route::group(['prefix' => 'user'], function(){
Route::get('{id}', ['uses' => 'UserController@getUser']);
Route::post('', ['uses' => 'UserController@saveUser']);
Route::get('', ['uses' => 'UserController@allUsers']);
Route::put('{id}',['uses' => 'UserController@updateUser']);
Route::delete('{id}', ['uses' => 'UserController@deleteUser']);
});
});
UserController.php:
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
class UserController extends Controller{
protected $user = null;
public function __construct(User $user){
$this->user = $user;
}
public function allUsers(){
return $this->user->allUsers();
}
public function getUser($id){
}
public function saveUser(){
return $this->user->saveUser();
}
public function updateUser($id){
}
public function deleteUser($id){
}
}
user.php的:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
public $hidden = ['venda','remember_token', 'created_at','updated_at'];
public $fillable = ['nome','email', 'venda'];
public function allUsers(){
return self::all();
}
public function saveUser(){
$input = Input::all();
echo 'aa';
$user = new User();
$user->fill($input);
$user->save();
return $user;
}
}