'未定义的变量:客户端(视图:C:\ wamp \ www \ myLSF \ resources \ views \ back \ clients \ index.blade.php)'

时间:2019-11-05 21:05:38

标签: php laravel

我正在视图/后退/客户端中创建index.blade.php来列出客户端。但是我遇到此错误。

未定义变量:客户端(视图:C:\ wamp \ www \ myLSF \ resources \ views \ back \ clients \ index.blade.php)

这是我的index.blade.php

set.seed(123)
dtf <- data.frame(round(cbind(index=sort(runif(20, -10, 10)), 
                                 v1=runif(20, 0, 5), 
                                 v2=runif(20, 5, 10)), 2))
ea <- nrow(dtf)/10

# Deciles shifted by 5
d <- rep(((1:10 + 4) %% 10) + 1, each=ea)

# Random index within decile
r <- c(replicate(10, sample(ea)))

cbind(dtf, z=dtf[order(d, r), -1])
#    index   v1   v2 z.v1 z.v2
# 12 -9.16 4.45 5.71 4.51 7.21
# 11 -9.09 3.46 7.07 4.82 5.23
# 14 -7.94 3.20 7.07 3.98 5.61
# 13 -5.08 4.97 6.84 3.45 8.99
# 15 -4.25 3.28 5.76 0.12 7.80
# 16 -3.44 3.54 5.69 2.39 6.03
# 17 -1.82 2.72 6.17 3.79 5.64
# 18 -0.93 2.97 7.33 1.08 8.77
# 19 -0.87 1.45 6.33 1.59 9.48
# 20  0.56 0.74 9.29 1.16 6.87
# 2   1.03 4.82 5.23 3.46 7.07
# 1   1.45 4.51 7.21 4.45 5.71
# 3   3.55 3.45 8.99 3.20 7.07
# 4   5.77 3.98 5.61 4.97 6.84
# 6   7.66 0.12 7.80 3.54 5.69
# 5   7.85 2.39 6.03 3.28 5.76
# 8   8.00 3.79 5.64 2.97 7.33
# 7   8.81 1.08 8.77 2.72 6.17
# 10  9.09 1.59 9.48 0.74 9.29
# 9   9.14 1.16 6.87 1.45 6.33

这是我的clientcontroller.php

 <table id="example1" class="table table-bordered table-hover">
            <thead>
            <tr>
              <th>#</th>
              <th>First Name </th>
              <th>Last Name</th>
              <th>Address</th>
              <th>Postal Code</th>
              <th>City</th>
               <th>Province</th>
               <th>Phone</th>


            </tr>
            </thead>

            <tbody>
          @foreach($clients as $client)


            <tr>
              <td>{{ $client->id }} </td>
              <td>{{ $client->firstname }}</td>
              <td>{{ $client->lastname }}</td>
              <td>{{ $client->address }}</td>
              <td>{{ $client->postalcode }}</td>
              <td>{{ $client->city }}</td>
              <td>{{ $client->province }}</td>
              <td>{{ $client->phoneno }}</td>

            </tr>

           @endforeach
            </tbody>

            <tfoot>
            <tr>
              <th>First Name </th>
              <th>Last Name</th>
              <th>Address</th>
              <th>Postal Code</th>
              <th>City</th>
               <th>Province</th>
               <th>Phone</th>
            </tr>
            </tfoot>
          </table>

这是我的client.php模型

class clientController extends Controller
{

public function list()
{

    $clients = client::get();

    return view('/back/clients/index', compact('clients'));
 }
}

在这里我在web.php中设置路由

class client extends Model
 {
  use Notifiable;
  @var

 protected $table='clients';
  protected $fillable= 
    ['firstname','lastname','address','postalcode',
   'city','province','phoneno'];

    }

1 个答案:

答案 0 :(得分:-1)

您需要将client模型导入到clientController.php文件中。

为此,请在顶部添加use App\client,如下所示:

use App\client;

class clientController extends Controller
{
    public function list()
    {
        $clients = client::get();

        return view('/back/clients/index', compact('clients'));
    }
}