小编He7*_*7nG的帖子

如何修复错误未找到基表或视图:1146表laravel关系表?

我是一个新的laravel我尝试在表之间创建多对多的关系,当我将数据插入数据库时​​出现问题我遇到了错误

Connection.php第713行中的QueryException:SQLSTATE [42S02]:找不到基表或视图:1146表'learn.category_posts'不存在(SQL:insert into category_posts(category_id,posts_id)values(4,))

任何人都可以帮助我.以下是我的迁移和代码:

2016_08_04_131009_create_table_posts.php

public function up()
{
    Schema::create('posts', function (Blueprint $table) {
        $table->increments('id');
        $table->text('title');
        $table->text('body');
        $table->timestamps();
    });
}
Run Code Online (Sandbox Code Playgroud)

2016_08_04_131053_create_table_categories.php

public function up()
{
    Schema::create('categories', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->timestamps();
    });
}
Run Code Online (Sandbox Code Playgroud)

2016_08_04_131413_create_table_category_posts.php

public function up()
{
    Schema::create('category_post', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('category_id')->unsigned();
        $table->integer('post_id')->unsigned();
        $table->foreign('category_id')->references('id')->on('categories')->onUpdate('cascade')->onDelete('cascade');
        $table->foreign('post_id')->references('id')->on('posts')->onUpdate('cascade')->onDelete('cascade');
        $table->timestamps();
    });
}
Run Code Online (Sandbox Code Playgroud)

和我的模特Posts.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Posts extends Model
{
    protected $table = 'posts';

    public function categories()
    {
        return …
Run Code Online (Sandbox Code Playgroud)

laravel laravel-5 laravel-5.2

7
推荐指数
6
解决办法
6万
查看次数

为什么我的表单打开不在laravel 5.1中工作?

大家好我有我的形式问题我正在写html表格,但它的错误,这是我的路线代码

Route::get('course','CourseController@index');
Run Code Online (Sandbox Code Playgroud)

这是我的CourseController:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class CourseController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('course.create');
    }
Run Code Online (Sandbox Code Playgroud)

这是我的观点课程/ create.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>Hello World</title>
    <link rel="stylesheet" type="text/css" href="">
</head>
<body>
<div class="container">
    {!! Form::open(array('route' => 'course.store')) !!}

        <input type="text"><br>
        <input type="password"><br>
    {!! Form::close() !!}
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

和错误:

Whoops, looks like something went wrong.
1/1 FatalErrorException in 818f720d4e075893d8198d2b0ff02e25 line …
Run Code Online (Sandbox Code Playgroud)

laravel laravel-5 laravel-5.1

1
推荐指数
1
解决办法
2232
查看次数

标签 统计

laravel ×2

laravel-5 ×2

laravel-5.1 ×1

laravel-5.2 ×1