简体   繁体   中英

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)

please see this link 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:

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(),
    ]);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM