找不到类“App\Http\Controllers\Search”

Tra*_*ick 2 php laravel

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

<?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);
 }
}
Run Code Online (Sandbox Code Playgroud)

cee*_*yoz 5

您遇到了命名空间问题。

您的控制器位于App\Http\Controllers命名空间中,因此默认情况下它会出现在该命名空间中。在您的控制器顶部,use Searchy;在现有行旁边添加一行use将使其工作,或者您可以Searchy以 a\开头来告诉 PHP 从命名空间根开始。

$rcrds = \Searchy::search(...);
Run Code Online (Sandbox Code Playgroud)