Support the ongoing development of Laravel.io →
Blade Database Laravel
0

Hello Is your problem only in data display? Please make sure the data is correct before running the blade file.

It's just necessary use dd method !

(To send codes, it is better to use the code sample feature)

0

@amirhossein256 yes my problem is only in data display

when i create a project it add successfully in the database (MySql) and i see all the fiels that i`ve created but in the view it wont show in list view or in grid view .

i have another section called** project report ** and i can see the data that i have on have in my database i dont why i can`t display it

here is my code Project Controller `{ /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index($view = 'grid') {

    if(\Auth::user()->can('manage project'))
    {
        return view('projects.index', compact('view'));
    }
    else
    {
        return redirect()->back()->with('error', __('Permission Denied.'));
    }
}

/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { if(\Auth::user()->can('create project')) { $users = User::where('created_by', '=', \Auth::user()->creatorId())->where('type', '!=', 'client')->get()->pluck('name', 'id'); $clients = User::where('created_by', '=', \Auth::user()->creatorId())->where('type', '=', 'client')->get()->pluck('name', 'id'); $clients->prepend('Select Client', ''); $users->prepend('Select User', ''); return view('projects.create', compact('clients','users')); } else { return redirect()->back()->with('error', __('Permission Denied.')); } }

/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) {

    if(\Auth::user()->can('create project'))
    {
        $validator = \Validator::make(
            $request->all(), [
                            'project_name' => 'required',
                            'project_image' => 'required',
                        ]
        );
        if($validator->fails())
        {
            return redirect()->back()->with('error', Utility::errorFormat($validator->getMessageBag()));
        }
        $project = new Project();
        $project->project_name = $request->project_name;
        $project->start_date = date("Y-m-d H:i:s", strtotime($request->start_date));
        $project->end_date = date("Y-m-d H:i:s", strtotime($request->end_date));
        if($request->hasFile('project_image'))
        {
            $imageName = time() . '.' . $request->project_image->extension();
            $request->file('project_image')->storeAs('projects', $imageName);
            $project->project_image      = 'projects/'.$imageName;
        }
        $project->client_id = $request->client;
        $project->budget = !empty($request->budget) ? $request->budget : 0;
        $project->description = $request->description;
        $project->status = $request->status;
        $project->estimated_hrs = $request->estimated_hrs;
        $project->tags = $request->tag;
        $project->created_by = \Auth::user()->creatorId();
        $project->save();

        if(\Auth::user()->type=='company'){

            ProjectUser::create(
                [
                    'project_id' => $project->id,
                    'user_id' => Auth::user()->id,
                ]
            );

            if($request->user){
                foreach($request->user as $key => $value) {
                    ProjectUser::create(
                        [
                            'project_id' => $project->id,
                            'user_id' => $value,
                        ]
                    );
                }
            }


        }else{
            ProjectUser::create(
                [
                    'project_id' => $project->id,
                    'user_id' => Auth::user()->creatorId(),
                ]
            );

            ProjectUser::create(
                [
                    'project_id' => $project->id,
                    'user_id' => Auth::user()->id,
                ]
            );

            if($request->user){
                foreach($request->user as $key => $value) {
                    ProjectUser::create(
                        [
                            'project_id' => $project->id,
                            'user_id' => $value,
                        ]
                    );
                }
            }

        }

`

index.blade.php

`@extends('layouts.admin') @section('page-title') {{('Manage Projects')}} @endsection @push('script-page') @endpush @section('breadcrumb') <li class="breadcrumb-item"><a href="{{route('dashboard')}}">{{('Dashboard')}}</a></li> <li class="breadcrumb-item">{{__('Projects')}}</li> @endsection @section('action-btn') <div class="float-end"> @if($view == 'grid') <a href="{{ route('projects.list','list') }}" data-bs-toggle="tooltip" title="{{__('List View')}}" class="btn btn-sm btn-primary"> <i class="ti ti-list"></i> </a>

    @else
        <a href="{{ route('projects.index') }}"  data-bs-toggle="tooltip" title="{{__('Grid View')}}" class="btn btn-sm btn-primary">
            <i class="ti ti-layout-grid"></i>
        </a>
    @endif


    {{------------ Start Filter ----------------}}
            <a href="#" class="btn btn-sm btn-primary action-item" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <i class="ti ti-filter"></i>
            </a>
            <div class="dropdown-menu  dropdown-steady" id="project_sort">
                <a class="dropdown-item active" href="#" data-val="created_at-desc">
                    <i class="ti ti-sort-descending"></i>{{__('Newest')}}
                </a>
                <a class="dropdown-item" href="#" data-val="created_at-asc">
                    <i class="ti ti-sort-ascending"></i>{{__('Oldest')}}
                </a>

                <a class="dropdown-item" href="#" data-val="project_name-desc">
                    <i class="ti ti-sort-descending-letters"></i>{{__('From Z-A')}}
                </a>
                <a class="dropdown-item" href="#" data-val="project_name-asc">
                    <i class="ti ti-sort-ascending-letters"></i>{{__('From A-Z')}}
                </a>
            </div>

        {{------------ End Filter ----------------}}

        {{------------ Start Status Filter ----------------}}
            <a href="#" class="btn btn-sm btn-primary action-item" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <span class="btn-inner--icon">{{__('Status')}}</span>
            </a>
            <div class="dropdown-menu  project-filter-actions dropdown-steady" id="project_status">
                <a class="dropdown-item filter-action filter-show-all pl-4 active" href="#">{{__('Show All')}}</a>
                @foreach(\App\Models\Project::$project_status as $key => $val)
                    <a class="dropdown-item filter-action pl-4" href="#" data-val="{{ $key }}">{{__($val)}}</a>
                @endforeach
            </div>
        {{------------ End Status Filter ----------------}}


    @can('create project')
        <a href="#" data-size="lg" data-url="{{ route('projects.create') }}" data-ajax-popup="true" data-bs-toggle="tooltip" title="{{__('Create New Project')}}" class="btn btn-sm btn-primary">
            <i class="ti ti-plus"></i>
        </a>
    @endcan
</div>

@endsection

`

menu.blade.php

<!-- Start Project --> @if(\Auth::user()->show_project() == 1) @if( Gate::check('manage project')) <li class="menu-item {{ ( Request::segment(1) == 'project' || Request::segment(1) == 'bugs-report' || Request::segment(1) == 'bugstatus' || Request::segment(1) == 'project-task-stages' || Request::segment(1) == 'calendar' || Request::segment(1) == 'timesheet-list' || Request::segment(1) == 'taskboard' || Request::segment(1) == 'timesheet-list' || Request::segment(1) == 'taskboard' || Request::segment(1) == 'project' || Request::segment(1) == 'projects'|| Request::segment(1) == 'time-tracker' || Request::segment(1) == 'project_report') ? 'active open' : ''}}"> <a href="#" class="menu-link menu-toggle"> <i class="menu-icon tf-icons ti ti-color-swatch"></i> <div data-i18n="{{__('Project System')}}">{{__('Project System')}}</div> </a> <ul class="menu-sub"> @can('manage project') <li class="menu-item {{Request::segment(1) == 'project' || Request::route()->getName() == 'projects.list' || Request::route()->getName() == 'projects.list' ||Request::route()->getName() == 'projects.index' || Request::route()->getName() == 'projects.show' || request()->is('projects/*') ? 'active' : ''}}"> <a href="{{route('projects.index')}}" class="menu-link"> <div data-i18n="{{__('Projects')}}">{{__('Projects')}}</div> </a> </li> @endcan

list.blade.php

<div class="row"> <div class="col-xl-12"> <div class="card"> <div class="card-body table-border-style"> <div class="table-responsive"> <table class="table datatable"> <thead> <tr> <th>{{__('Project')}}</th> <th>{{__('Status')}}</th> <th>{{__('Users')}}</th> <th>{{__('Completion')}}</th> <th class="text-end">{{__('Action')}}</th> </tr> </thead> <tbody> @if(isset($projects) && !empty($projects) && count($projects) > 0) @foreach ($projects as $key => $project) <tr> <td> <div class="d-flex align-items-center"> <img {{ $project->img_image }} class="wid-40 rounded me-3" alt="avatar image"> <p class="mb-0"><a href="{{ route('projects.show',$project) }}" class="name mb-0 h6 text-sm">{{ $project->project_name }}</a></p> </div> </td> <td class=""> <span class="badge bg-{{\App\Models\Project::$status_color[$project->status]}} p-2 px-3 rounded">{{ __(\App\Models\Project::$project_status[$project->status]) }}</span> </td> <td class=""> <div class="avatar-group" id="project_{{ $project->id }}"> @if(isset($project->users) && !empty($project->users) && count($project->users) > 0) @foreach($project->users as $key => $user) @if($key < 3) <a href="#" class="avatar rounded-circle"> <img @if($user->avatar) src="{{asset('/storage/uploads/avatar/'.$user->avatar)}}" @else src="{{asset('/storage/uploads/avatar/avatar.png')}}" @endif title="{{ $user->name }}" style="height:36px;width:36px;"> </a> @else @break @endif @endforeach @if(count($project->users) > 3) <a href="#" class="avatar rounded-circle avatar-sm"> <img avatar="+ {{ count($project->users)-3 }}" style="height:36px;width:36px;"> </a> @endif @else {{ __('-') }} @endif </div> </td> <td class="text-end"> <h5 class="mb-0 text-success">{{ $project->project_progress()['percentage'] }}</h5> <div class="progress mb-0"> <div class="progress-bar bg-{{ $project->project_progress()['color'] }}" style="width: {{ $project->project_progress()['percentage'] }};"></div> </div> </td> <td class="text-end"> <span> @can('edit project') <div class="action-btn bg-warning ms-2"> <a href="#" class="mx-3 btn btn-sm d-inline-flex align-items-center" data-url="{{ route('invite.project.member.view', $project->id) }}" data-ajax-popup="true" data-size="lg" data-bs-toggle="tooltip" title="{{__('Invite User')}}" data-title="{{__('Invite User')}}"> <i class="ti ti-send text-white"></i> </a> </div> @endcan @can('edit project') <div class="action-btn bg-info ms-2"> <a href="#" class="mx-3 btn btn-sm d-inline-flex align-items-center" data-url="{{ URL::to('projects/'.$project->id.'/edit') }}" data-ajax-popup="true" data-size="lg" data-bs-toggle="tooltip" title="{{__('Edit')}}" data-title="{{__('Edit Project')}}"> <i class="ti ti-pencil text-white"></i> </a> </div> @endcan @can('delete project') <div class="action-btn bg-danger ms-2"> {!! Form::open(['method' => 'DELETE', 'route' => ['projects.user.destroy', [$project->id,$user->id]]]) !!} <a href="#" class="mx-3 btn btn-sm align-items-center bs-pass-para" data-bs-toggle="tooltip" title="{{__('Delete')}}"><i class="ti ti-trash text-white"></i></a> {!! Form::close() !!} </div> @endcan </span> </td> </tr> @endforeach @else <tr> <th scope="col" colspan="7"><h6 class="text-center">{{__('No Projects Found.')}}</h6></th> </tr> @endif </tbody> </table> </div> </div> </div> </div> </div>

0
moderator

Hello @abdellahhajjam ,

For the overview it can be useful to post only the related code. Because your question is about displaying and you already verified that it is in your database you could show only the index function and blade.

In your index function of the controller you only return the view but don't load the data. You can do it with something like: Project::orderBy('project_name ')->get(); (this order your data on project_name).

That will result in this function.

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index($view = 'grid')
    {

        if(\Auth::user()->can('manage project'))
        {
            $projects = Project::orderBy('project_name ')->get();
            return view('projects.index', compact('view', 'projects'));
        }
        else
        {
            return redirect()->back()->with('error', __('Permission Denied.'));
        }
    }

Ps. I have updated your last post to have code blocks.

abdellahhajjam liked this reply

1

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.