foxriver123

6611 经验值

恩,好的。先学习下markdown = =

laravel5.5的童鞋请把在控制器重写AuthenticatesUsers里面的guard方法

这种有点认证很诡异,如果我是用户的话,我会想你这样什么网站啊是不是想盗取我的账户信息,个人觉得还是前面Oauth2.0来的实在? so what u guys think?

Bearer后面有个空格哈哈 搞了我3个小时

为什么我的代码贴出来是这个形状。。

web.php

Route::group(['prefix'=> 'api'],function(){
    Route::get('/user/{id}/{method}', function ($id) {
        $user = App\User::find($id);
        return new App\Http\Resources\User($user);
    });
    Route::get('/users/{method}',function(){
        $users = App\User::all();
        return new App\Http\Resources\UserCollection($users);
    });
});

User.php

class User extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    private $status = 'success';
    private $code = 200;
    public function toArray($request)
    {
        if(method_exists($this, $request->method) && $method = $request->method){
            return $this->$method();
        }
        $this->status = 'failed';
        $this->code = '404';
    }
    public function getUser(){
        return [
            'username' => $this->name,
        ];
    }

    public function getUserEmail(){
        return [
            'username' => $this->email,
        ];
    }

    public function with($request){
        return [
            'status' => $this->status,
            'code'   => $this->code,
        ];
    }

}

UserCollection.php

class UserCollection extends ResourceCollection
{
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    private $status = 'success';
    private $code = 200;
    public function toArray($request)
    {
        if(!method_exists(User::class, $request->method)){
            $this->status = 'urlNotFound';
            $this->code = '404';
            return [];
        }
        return parent::toArray($request);
    }

    public function with($request){
        return [
            'status' => $this->status,
            'code'   => $this->code,
        ];
    }
}

这个应该可以解决问题

这是多么2的问题!当我没问哈哈!!!!

jelly 我要买终身,已是半年会员如何操作 谢谢

public function normalizeTopics(array $topics){

    return collect($topics)->map( function($topic){

        if(is_numeric($topic) && $topic_number = (int)$topic){
            if( $newTopic = Topic::find($topic_number) ){
                $newTopic->increment('questions_count');
                return $topic_number;
            }
            
        }

        if($newTopic = Topic::where('name',$topic)->first()){
            $newTopic->increment('questions_count');
            return $newTopic->id;
        }
        
        $newTopic = Topic::create(['name'=>$topic , 'questions_count'=>1]);
        return $newTopic->id;
    })->toArray();
}

解决All

@jelly 团队订阅是啥意思,是有更高级的更实战的内容吗?能介绍下吗?说句心里话laravist是我见过最好的学习站,没有之一,下个月15号终生会员没得说!!还有就是我已经是半年会员成为终生会员有咋扣吗。wait me happy hacking yeah!