所以,伙计们,这是我在项目中遇到的错误。
解析错误:语法错误,文件意外结尾,预期函数(T_FUNCTION)或const(T_CONST) https://i.imgur.com/i4iMnze.jpg
视频模型代码:-
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Video extends Model
{
public function videos(){
return $this->belongsTo("App\Category");
}
类别模型的代码:-
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
}
layouts.app的代码:-
<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Laravel') }}</title>
<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
<body>
<div id="app">
<nav class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<!-- Collapsed Hamburger -->
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#app-navbar-collapse">
<span class="sr-only">Toggle Navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- Branding Image -->
<a class="navbar-brand" href="{{ url('/') }}">
{{ config('app.name', 'Laravel') }}
</a>
</div>
<div class="collapse navbar-collapse" id="app-navbar-collapse">
<!-- Left Side Of Navbar -->
<ul class="nav navbar-nav">
</ul>
<!-- Right Side Of Navbar -->
<ul class="nav navbar-nav navbar-right">
<!-- Authentication Links -->
@if (Auth::guest())
<li><a href="{{ route('login') }}">Login</a></li>
<li><a href="{{ route('register') }}">Register</a></li>
@else
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
{{ Auth::user()->name }} <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
Logout
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
</li>
</ul>
</li>
@endif
</ul>
</div>
</div>
</nav>
@yield('content')
</div>
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}"></script>
vido.blade.php的代码
@extends('layouts.app')
@section('content')
<div class="col-lg-4 col-lg-offset-1">
<form id="addproduct" class="" enctype="multipart/form-data" method="post">
<input type="hidden" name="_token" value="{{csrf_token()}}">
<div class="form-group">
<label for="type">Custom Name</label>
<input type="text" class="form-control" name="vid_name" id="name" placeholder="Product Name">
</div>
<div class="form-group">
<label for="type">Video ID</label>
<input type="text" class="form-control" name="vid_id" id="Quantity" placeholder="Price">
</div>
<div class="form-group">
<select class="form-control category" name="category" id="">
<option value="">--select category--</option>
@foreach($categories as $category)
<option value="{{$category->id}}">{{$category->category}}</option>
@endforeach
</select>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</div>
</div>
@endsection
视频控制器代码:-
public function video(){
$categories= \App\Category::all();
return view('admin.video')
->with("categories",$categories);
}
public function addVideo(Request $request){
$un= new \App\Video;
$un->custom_name= $request->get('vid_name');
$un->vid_id= $request->get('vid_id');
$un->category= $request->get('category');
$un->feature_status="0";
$un->status="1";
$un->save();
if($un){
return redirect()->back();
}
}
所以伙计们,我想我添加了知道我的项目错误所需的所有代码。另一件事是,当我从视频表格中删除类别选项时,它可以完美运行。我现在不知道这是代码中的错误还是模型中的关系错误。请帮助...
预先感谢
答案 0 :(得分:-2)
namespace App;
use Illuminate\Database\Eloquent\Model;
class Video extends Model
{
public function videos() {
return $this->belongsTo("App\Category");
}
}