Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 简单Foreach图像拉维_Php_Html_Laravel - Fatal编程技术网

Php 简单Foreach图像拉维

Php 简单Foreach图像拉维,php,html,laravel,Php,Html,Laravel,我接收他们上传的每个图像的所有用户活动,但我也希望在这个foreach中与表一起接收图像 在我的数据库中,users表中有5列,它们是doc1doc2doc3doc4和doc5。当我收到他们制作的图像以及正确的描述时,无需登录每个用户帐户 事实上,这其中有5个控制器,请不要注意混乱^^我是编程新手 public function mudar_doc1(Request $request) { // getting all of the post data $fi

我接收他们上传的每个图像的所有用户活动,但我也希望在这个foreach中与表一起接收图像

在我的数据库中,
users
表中有5列,它们是
doc1
doc2
doc3
doc4
doc5
。当我收到他们制作的图像以及正确的描述时,无需登录每个用户帐户

事实上,这其中有5个控制器,请不要注意混乱^^我是编程新手

 public function mudar_doc1(Request $request) {
    // getting all of the post data
            $file = array('image' => Input::file('image'));
    // setting up rules
            $rules = array('image' => 'required|image',); //mimes:jpeg,bmp,png and for max size max:10000
    // doing the validation, passing post data, rules and the messages
            $validator = Validator::make($file, $rules);
            if ($validator->fails()) {
    // send back to the page with the input data and errors
                return Redirect::to('userp')->withInput()->withErrors($validator);
            } else {
    // checking file is valid.
                if (Input::file('image')->isValid()) {
                    $destinationPath = 'uploads'; // upload path
                    $extension = Input::file('image')->getClientOriginalExtension(); // getting image extension

                    $extensoes = array("png", "jpeg", "jpg", "gif");
                    $resVal = in_array($extension, $extensoes);
                    if ($resVal) {

                    } else {
                        Session::flash('error', 'O upload não foi realizado com sucesso.');
                        return Redirect::to('userp');
                    }

                    $fileName = rand(11111, 99999) . '.' . $extension; // renameing image
                    Input::file('image')->move($destinationPath, $fileName); // uploading file to given path
                    $doc1 = asset($destinationPath . '/' . $fileName);
                    User::where('id', \Auth::user()->id)->update(['doc1' => $doc1]);
    // sending back with message
                    Session::flash('success', 'ID Card Front Successfully Added!');
                    \App\RegistroAtividade::addAtividade('Cartao ID Frente');

                    return Redirect::to('userp');
                } else {
    // sending back with error message.
                    Session::flash('error', 'O upload não foi realizado com sucesso.');
                    return Redirect::to('userp');
                }
            }
        }


               <tbody>
                @foreach($allAtividades as $atividade)
                <tr>
                    <td>{{$atividade['id']}}</td>
                    <td>{{$atividade->getUser()->name}}</td>
                    <td>{{$atividade['ip']}}</td>
                    <td>{{$atividade['description']}}</td>
                    <td>{{$atividade['created_at']}}</td>
                </tr>
              </tbody>
                @endforeach
公共功能mudar_doc1(请求$Request){ //获取所有post数据 $file=array('image'=>Input::file('image'); //制定规则 $rules=array('image'=>'required | image',);//mimes:jpeg、bmp、png和最大大小max:10000 //进行验证,传递post数据、规则和消息 $validator=validator::make($file,$rules); 如果($validator->fails()){ //将输入数据和错误发送回页面 返回Redirect::to('userp')->withInput()->withErrors($validator); }否则{ //检查文件是否有效。 if(Input::file('image')->isValid(){ $destinationPath='uploads';//上传路径 $extension=Input::file('image')->getClientOriginalExtension();//获取图像扩展名 $extensoes=数组(“png”、“jpeg”、“jpg”、“gif”); $resVal=in_数组($extension,$extensoes); 如果($resVal){ }否则{ 会话::flash('error','O upload nãO foi realizado com successo'); 返回Redirect::to('userp'); } $fileName=rand(111119999)。'.$extension;//重命名图像 Input::file('image')->move($destinationPath,$fileName);//将文件上载到给定路径 $doc1=资产($destinationPath.'/'.$fileName); User::where('id',\Auth::User()->id)->update(['doc1'=>$doc1]); //发回消息 会话::flash('success','ID Card Front Successfully Added!'); \App\RegistroAtividade::addAtividade('Cartao ID Frente'); 返回Redirect::to('userp'); }否则{ //正在发送回错误消息。 会话::flash('error','O upload nãO foi realizado com successo'); 返回Redirect::to('userp'); } } } @foreach($allAtividades作为$atividade) {{$atividade['id']} {{$atividade->getUser()->name} {{$atividade['ip']} {{$atividade['description']} {{$atividade['created_at']} @endforeach
我在您的代码中没有看到太多关于图像/控制器/视图或数据的参考资料,请更新您的问题,我将更新此答案


我想作一些重要的说明
  • 我建议你抽出一些时间来读一下这本书
  • 然后,如果您还没有,您可以创建
    Actividade
    Eloquent
  • Actividade
    Eloquent中,您可以分配
    user
    这样的关系
类活动{
//...
公共函数用户(){
返回$this->belongsTo(App\User::class,'User_id');
}
}
这里的user方法将通过使用
actividade
表中的user_id列返回用户[如果您已经正确设置了它],这将更容易获取活动
$actividade->user->name
,而不是
$actividade->getUser()->name

按照这种方法,您可以拥有一个ImagesEloquent类,该类具有
activities
方法,该方法与具有用户的活动和具有活动的用户的活动类似:

使用此方法(骨架)将非常简单:

@foreach(Image::find(1)->activities as $_activity){
  <td><img src="{{Image::find(1)->filename}}"/></td> <!-- just an example here -->
  <td>{{$_activity->id}}</td>
  <td>{{$_activity->user->name}}</td>
  <td>{{$_activity->ip}}</td>
  <td>{{$_activity->description}}</td>
  <td>{{$_activity->created_at}}</td>
@endforeach
@foreach(Image::find(1)->活动作为$\u活动){
文件名}}”/>
{{$\u活动->id}
{{$\u活动->用户->名称}
{{$\活动->ip}
{{$\u活动->描述}
{{$\u活动->在}创建}
@endforeach
获取图像,可以获取其活动,然后每个活动都有用户


了解这一点需要一点时间(一个小时左右),但我认为这将为您节省数百个小时的时间,并为您提供一种更干净的代码。

评论不用于扩展讨论;本次对话已经结束。