简体   繁体   English

如何在迁移到控制器时检索视图数据?

[英]How to retrieve view data in migration to controller?

I'm completely new to the views.我对这些观点完全陌生。 I don't know how to get the view in controller.我不知道如何在控制器中获取视图。 Below given is the view i have created using migration.下面给出的是我使用迁移创建的视图。 I want to fetch the data in this view to my controller.我想将此视图中的数据获取到我的控制器。 How to do that?怎么做? Any help is appreciated.任何帮助表示赞赏。

 class CourseMarketView extends Migration
 {
     public function up()
        {
            DB::statement("
          CREATE VIEW course_market_view AS
          (
            SELECT 
    users.id,
    users.name,
    course.courseId,
    course.courseUniqueName,
    skills.id,
    skills.skill,
    subjects.id,
    subjects.subject
     FROM users 
      LEFT JOIN course ON course.courseId=users.id
      LEFT JOIN skills ON skills.id=users.id
      LEFT JOIN subjects ON subjects.id = users.id

          )
        ");
        }
  }

Controller控制器

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\DB;
use App\Models\User;
use App\Models\Course;
use App\Models\Skill;
use App\Models\Subject;

class CourseMarketController extends Controller
{
    public function getcoursebysubjectID(){

        $users = User::select("*")
                        ->get()
                        ->toArray();             
        dd($users);    
    }
}

course table课程表

Schema::create('course', function (Blueprint $table) {
            $table->integer('courseId')->autoIncrement();
            $table->string('courseDisplayName');
            $table->string('courseUniqueName')->unique();
            $table->string('courseAddedBy');
            $table->dateTime('createdOn');
            $table->dateTime('lastUpdated');
            $table->softDeletes();
        });

you can do that by creating new model like this :-你可以通过创建这样的新模型来做到这一点:-

class CourseMarketView extends Eloquent {

    protected $table = 'course_market_view';
}

in controller you can do that :-在控制器中,您可以这样做:-

CourseMarketView::all();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在视图中检索数据,独立于Codeigniter中的控制器 - how to retrieve data in view Independent of controller in codeigniter 如何从视图中检索搜索结果数据对象到 controller - How to retrieve search result data objects from view to controller 如何从控制器中的PHP传递的视图中检索多个数据? - How to retrieve multiple data at view passed from controller in php? 在视图中或仅在控制器中检索模型数据是否正确? - Is it correct to retrieve Model data in a View, or just in the Controller? Laravel 5-如何在控制器中获取Auth用户ID,检索用户数据并在视图中显示该数据 - Laravel 5 - How to get Auth user ID in controller, retrieve user data and display that data in view 如何将视图数据传递给控制器​​? - How to pass view data to controller? 如何检索通过ajax从控制器发送到视图的数组? - how to retrieve the array which is send from controller to the view through ajax? 如何从控制器中检索参数值以进行查看? - How do I retrieve the value of parameter from controller to view? 如何在Laravel 5框架中检索数据 - How to retrieve data in view of Laravel 5 framework Codeigniter-在视图中获取表数据,发送表数据并在控制器上检索表数据 - Codeigniter - Get table data in view, send table data and retrieve table data on controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM