這是我在 .env DB_DATABASE=cricbangla 中的資料庫名稱
這是我的資料庫和所有表的螢屏截圖 這是我的資料庫 的影像 您可以看到沒有名為batter_firsts 的表,我不想要任何具有此名稱的表
我正在 laravel-8 中做一個 CRUD 專案,在那里我創建了一個表名batterfirst.php
Schema::create('batterfirst', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->integer('runs');
$table->integer('balls');
$table->integer('sixs');
$table->integer('fours');
$table->timestamps();
});
我的 web.php 在哪里
<?php
use App\Http\Controllers\BatterFirstController;
Route::get('/', function () {
return view('welcome');
});
Route::resource('BatterFirst', BatterFirstController::class);
我的模型名稱是 BatterFirst.php
class BatterFirst extends Model
{
use HasFactory;
protected $fillable = [
'name', 'runs', 'balls', 'sixs', 'fours'
];
}
我的控制器是 BatterFirstController.php
<?php
namespace App\Http\Controllers;
use App\Models\BatterFirst;
use Illuminate\Http\Request;
class BatterFirstController extends Controller
{
public function index()
{
$data = BatterFirst::latest()->paginate(5);
return view('BatterFirst.index',compact('data'))
->with('i', (request()->input('page', 1) - 1) * 5);
}
public function create()
{
return view('BatterFirst.create');
}
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'runs' => 'required',
'balls' => 'required',
'sixs' => 'required',
'fours' => 'required',
]);
BatterFirst::create($request->all());
return redirect()->route('BatterFirst.index')
->with('success','Batter created successfully.');
}
public function show(BatterFirst $batterFirst)
{
return view('BatterFirst.show',compact('batterfirst'));
}
public function edit(BatterFirst $batterFirst)
{
return view('BatterFirst.edit',compact('batterfirst'));
}
public function update(Request $request, BatterFirst $batterFirst)
{
$request->validate([
'name' => 'required',
'runs' => 'required',
'balls' => 'required',
'sixs' => 'required',
'fours' => 'required',
]);
$batterFirst->update($request->all());
return redirect()->route('BatterFirst.index')
->with('success','Batter updated successfully');
}
public function destroy(BatterFirst $batterFirst)
{
$batterFirst->delete();
return redirect()->route('BatterFirst.index')
->with('success','Batter deleted successfully');
}
}
這是我在 BatterFirst 檔案夾中的 index.php 檔案 BatterFirst/index.blade.php
@extends('BatterFirst.layout')
@section('content')
<div class="row" style="margin-top: 5rem;">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Laravel 8 CRUD Example from scratch - laravelcode.com</h2>
</div>
<div class="pull-right">
<a class="btn btn-success" href="{{ route('BatterFirst.create') }}"> Create New Post</a>
</div>
</div>
</div>
@if ($message = Session::get('success'))
<div hljs-string">">
<p>{{ $message }}</p>
</div>
@endif
<table hljs-string">">
<tr>
<th>No</th>
<th>Name</th>
<th>Runs</th>
<th>Balls</th>
<th>Sixs</th>
<th>Fours</th>
<th>Strick Rate</th>
</tr>
@foreach ($data as $key => $value)
<tr>
<td>{{ $i }}</td>
<td>{{ $value->name }}</td>
<td>{{ $value->runs }}</td>
<td>{{ $value->overs }}</td>
<td>{{ $value->balls }}</td>
<td>{{ $value->sixs }}</td>
<td>{{ $value->fours }}</td>
{{-- <td>{{ $value->runs/$value->balls*100 }}</td> --}}
<td>@if ($value->runs > 0 and $value->runs ==0)
{{ $value->runs*100 }}
@elseif ($value->balls>0 and $value->runs ==0)
{{ $value->balls*$value->runs }}
@elseif ($value->balls==0 and $value->runs ==0)
{{ $value->balls * $value->runs }}
@elseif ($value->runs>0 and $value->balls>=0)
{{ $value->runs/$value->balls*100 }}
@endif
</td>
<td>
<form action="{{ route('BatterFirst.destroy',$value->id) }}" method="POST">
<a hljs-string">" href="{{ route('BatterFirst.show',$value->id) }}">Show</a>
<a hljs-string">" href="{{ route('BatterFirst.edit',$value->id) }}">Edit</a>
@csrf
@method('DELETE')
<button type="submit" hljs-string">">Delete</button>
</form>
</td>
</tr>
@endforeach
</table>
{!! $data->links() !!}
@endsection
這是我的 BatterFirst/create.blade.php 檔案
@extends('BatterFirst.layout')
@section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Add New Product</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('BatterFirst.index') }}"> Back</a>
</div>
</div>
</div>
@if ($errors->any())
<div hljs-string">">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<form action="{{ route('BatterFirst.store') }}" method="POST">
@csrf
<div hljs-string">">
<div hljs-number">12 col-sm-12 col-md-12">
<div hljs-string">">
<strong>Name:</strong>
<input type="text" name="name" hljs-string">" placeholder="Enter Name">
</div>
</div>
<div hljs-number">12 col-sm-12 col-md-12">
<div hljs-string">">
<strong>Runs:</strong>
<input type="number" name="runs" hljs-string">" placeholder="Enter Runs">
</div>
</div>
<div hljs-number">12 col-sm-12 col-md-12">
<div hljs-string">">
<strong>Balls:</strong>
<input type="number" name="balls" hljs-string">" placeholder="Enter Balls">
</div>
</div>
<div hljs-number">12 col-sm-12 col-md-12">
<div hljs-string">">
<strong>Sixs:</strong>
<input type="number" name="sixs" hljs-string">" placeholder="Enter Sixs">
</div>
</div>
<div hljs-number">12 col-sm-12 col-md-12">
<div hljs-string">">
<strong>Fours:</strong>
<input type="number" name="fours" hljs-string">" placeholder="Enter Fours">
</div>
</div>
<div hljs-number">12 col-sm-12 col-md-12 text-center">
<button type="submit" hljs-string">">Submit</button>
</div>
</div>
</form>
@endsection
我不知道為什么會出現這個問題。注:我剛開始學習laravel
uj5u.com熱心網友回復:
它正在尋找正確的命名表,因為你在駱駝中擁有它,所以你應該可以batter_first通過下面的模型來改變它;
class BatterFirst extends Model
{
use HasFactory;
protected $table = 'batterfirst';
protected $fillable = [
'name', 'runs', 'balls', 'sixs', 'fours'
];
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/331015.html
上一篇:我如何回圈使用Laravel刀片中的碳從今天開始獲取未來10天的日期
下一篇:洗掉現有的Where子句
