DB :: table('table')-> select返回空字符串Laravel 6

时间:2019-12-07 16:40:50

标签: laravel vue.js

我正在将Laravel 6与Vue axios一起使用,我想用我的“ fjl_groups”表中的内容填充表单选择。但是每次我检查控制台的结果时,它都会返回一个空字符串,这是为什么?我的Laravel日志也未返回任何错误,所以我不知道发生了什么。

Vue的角色

<b-col cols="4">
    <label for="editorial">Group</label>
    <b-form-select v-model="group" :options="groups" id="groups" name="groups"></b-form-select>
</b-col>

<script>
export default {
    data() {
        return {
            group: null,
            groups: [{
                value: null,
                text: 'Select'
            }]
        }
    },

    created(){
        axios.get('/clubs/create')
            .then(res => {
                this.groups = res.data;
                console.log(this.groups);
            }).catch(e => {
                console.log(e);
            })
    },
    }
}
</script>

我有一个俱乐部,我想从我在数据库中添加的俱乐部为其分配一个小组,这就是为什么我有这样的俱乐部。

我的控制器(ClubsController)


use Illuminate\Support\Facades\DB;
use App\Models\Club;
use App\Models\Group;
    public function create(Request $request)
    {
        if($request->ajax()){
            DB::table('fjl_groups')->select('id as value', 'nom as text')->get();
        }
        else{
            return view('clubs.create');
        }
    }

组模型

class Group extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'fjl_groups';
    public $timestamps = false;
}

1 个答案:

答案 0 :(得分:1)

您没有返回值。您只是在执行选择。

尝试将其退回:

for (auto sv : v | static_cast<std::string_view>) {
    // do something with std::string_view
}