gpt4 book ai didi

php - 未找到类 'App\Http\Controllers\Search'

转载 作者:行者123 更新时间:2023-12-02 20:44:53 25 4
gpt4 key购买 nike

我是 Laravel 新手,我们正在尝试将 ( https://github.com/TomLingham/Laravel-Searchy ) 添加到我们的项目 ( https://github.com/wvulibraries/rockefeller-css/tree/trying-searchy ) 以允许搜索表中的多个字段。我可以看到该包作为 tom-lingham 位于供应商文件夹中,由于某种原因我什至无法使用它。我在 DataViewController.php 第 79 行收到 FatalThrowableError:未找到类“App\http\Controllers\Search”。我按照 github 存储库中的说明进行操作。如有任何建议,我们将不胜感激。

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
// Import the table and collection models
use App\Table;
use App\Collection;
use Illuminate\Support\Facades\Auth;
/**
* The controller is responsible for showing the cards data
*/
class DataViewController extends Controller {
/**
* Constructor that associates the middlewares
*
* @return void
*/
public function __construct(){
// Middleware to check for authenticated
$this->middleware('auth');
}
/**
* Show the data from the selected table
*/
public function index(Request $request, $curTable){
// Get the table entry in meta table "tables"
$curTable = Table::find($curTable);
if(!$curTable->hasAccess){
return redirect()->route('home')->withErrors(['Table is disabled']);
}
// Get and return of table doesn't have any records
$numOfRcrds = DB::table($curTable->tblNme)->count();
// check for the number of records
if ($numOfRcrds == 0){
return redirect()->route('home')->withErrors(['Table does not have any records.']);
}
// Get the records 30 at a time
$rcrds = DB::table($curTable->tblNme)->paginate(30);
// retrieve the column names
$clmnNmes = DB::getSchemaBuilder()->getColumnListing($curTable->tblNme);
// return the index page
return view('user.data')->with('rcrds',$rcrds)
->with('clmnNmes',$clmnNmes)
->with('tblNme',$curTable->tblNme)
->with('tblId',$curTable);
}
public function show(Request $request, $curTable, $curId){
// Get the table entry in meta table "tables"
$curTable = Table::find($curTable);
if(!$curTable->hasAccess){
return redirect()->route('home')->withErrors(['Table is disabled']);
}
// Check if search string and column were passed
if (strlen($curId) != 0) {
$numOfRcrds = DB::table($curTable->tblNme)
->where('id', '=', $curId)
->count();
// check for the number of records
if ($numOfRcrds == 0){
return redirect()->route('home')->withErrors(['Search Yeilded No Results']);
}
else {
// $rcrds = DB::table($curTable->tblNme)
// ->where('id', '=', $curId)
// ->get();
$rcrds = Searchy::search($curTable->tblNme)->fields('id')->query($curId)->get();
}
}
else {
return redirect()->route('home')->withErrors(['Invalid ID']);
}
// retrieve the column names
$clmnNmes = DB::getSchemaBuilder()->getColumnListing($curTable->tblNme);
// return the index page
return view('user.show')->with('rcrds',$rcrds)
->with('clmnNmes',$clmnNmes)
->with('tblNme',$curTable->tblNme)
->with('tblId',$curTable);
}
}

最佳答案

您遇到了命名空间问题。

您的 Controller 位于 App\Http\Controllers 命名空间中,因此默认情况下它会在该命名空间中查找。在 Controller 顶部,在现有的 use 行旁边添加 use Searchy; 行将使其正常工作,或者您可以在前面加上 Searchy 使用 \ 告诉 PHP 从命名空间根开始。

$rcrds = \Searchy::search(...);

关于php - 未找到类 'App\Http\Controllers\Search',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44762032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com