简体   繁体   English

想显示投资组合图片,但我遇到了一些错误

[英]want to show portfolio images but i am facing some error

Want to show portfolio images but I am facing some error and how to resolve this issue?想要显示投资组合图像,但我遇到了一些错误,如何解决这个问题?

Error错误

Undefined variable: portfolio (View: C:\xampp\htdocs\sigma-delta\resources\views\front_end\project.blade.php)未定义变量:投资组合(查看:C:\xampp\htdocs\sigma-delta\resources\views\front_end\project.blade.php)

please see this link https://flareapp.io/share/V7jQoLPb#F48请参阅此链接https://flareapp.io/share/V7jQoLPb#F48

controller

public function Projectaction(Request $request){

    $query=$request->get('query');   
       if($query == 'All')
       {
           $data['portfolio']=DB::table('category')
                ->join('projects', 'category.id', '=', 'projects.Category_id')
                ->select('projects.*', 'category.*')->get();
       }
       else if($query != 'All')
       {
           $data['portfolio']= DB::table('category')
              ->join('projects', 'category.id', '=', 'projects.Category_id')
              ->select('projects.*', 'category.*')
              ->where('category.category_name', $query)
              ->get();
       }

       return Response::json(array('response'=>true,'html' =>
              View::make('front_end/project',$data)->render()));

    }

Route

    Route::get('Project','FrontController@project');
    Route::get('projectaction','FrontController@projectaction');
    Route::get('Contact-Us','FrontController@Contact');

html view

<div class="portfolio masonry p-3-cols p-style3" id="masonry">
    @foreach($portfolio  as  $portfolios)
        <div class="portfolio-item ">
            <figure>
                <img alt="" src="{{$portfolios->image}}">
                <figcaption>
                     <div class="port-captions">
                          <h4><a href="single-portfolio.php">{{$portfolios->project_name}}</a></h4>
                     </div>
                     <div class="icon-links">
                          <a href="single-portfolio.php" class="link"><i class="fa fa-link"></i></a>
                          <a href="{{$portfolios->image}}" class="zoom" title="Quality Products for 
                    Companies"><i class="fa fa-search-plus"></i></a>
                    </div>
                </figcaption>           
            </figure>
        </div>
    @endforeach

ajax

$(document).ready(function() {
    fetch_customer_data("All");

    function fetch_customer_data(query) {
        $.ajax({
            type: 'get',
            url: '{{URL::to("projectaction")}}',
            data: {
                query: query
            },
            dataType: 'json',
            success: function(data) {
                console.log('success');
                $('#portfolio').html(data.html);
            },
            error: function(data) {
                console.log('error');
                console.log(data.responseText);
           },
            done: function() {
                $('#portfolio').unblock();
           }
        });
    }
    $(".filter-button").click(function() {
        var value = $(this).attr('data-filter');

        if (value == "All") {
            fetch_customer_data(value);
            $('.filter').toggle();
        } else {
            $(".filter").not('.' + value).toggle();
            $('.filter').filter('.' + value).toggle();
            fetch_customer_data(value);
        }
    });
    if ($(".filter-button").removeClass("active")) {
        $(this).removeClass("active");
    }
    $(this).addClass("active");

});

Try to refactor your controller a bit:尝试重构您的 controller 一点:

public function Projectaction(Request $request)
{
    $query = $request->get('query');

    if ($query == 'All') {
        $portfolio = DB::table('category')
            ->join('projects', 'category.id', '=', 'projects.Category_id')
            ->select('projects.*', 'category.*')
            ->get();
    } else {
        $portfolio = DB::table('category')
            ->join('projects', 'category.id', '=', 'projects.Category_id')
            ->select('projects.*', 'category.*')
            ->where('category.category_name', $query)
            ->get();
    }

    return Response::json([
        'response' => true,
        'html' => View::make('front_end/project', ['portfolio' => $portfolio])->render(),
    ]);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在咕unt中遇到以下错误 - I am facing the below error in grunt 我面临一个错误 ReferenceError: Paginator is not defined - I am facing a error ReferenceError: Paginator is not defined 为什么我在语音RSS API上遇到一些问题 - Why I am facing some problem with voice RSS api 我正在使用Bootstrap产品组合部分,想删除“ ALL”第一个标签并选择类别 - I am using Bootstrap portfolio section, want to remove 'ALL' first tab and make the category selected 我想用 react js 创建一些关于在窗口中添加字符串的程序,但是我遇到了错误 - I want to create some program with react js, about adding strings in window, but I am having an error 包含页面后,我面临ajax错误(未找到) - After including page I am facing ajax error (Not Found) 我面临 500 内部服务器错误! 对于 ajax 代码 - i am facing 500 Internal server error! for a ajax code 我正面临一个错误 net::ERR_ABORTED 401(未经授权) - I am facing an error net::ERR_ABORTED 401 (Unauthorized) React 新手,我在 React 中遇到了这个启动错误 - New to React i am facing this start error in react 我在下面的代码中遇到未定义的阅读长度错误 - I am facing an undefined reading length error in my code below
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM