English 中文(简体)
无法利用拉韦的活wi和lade取数据
原标题:Unable to retrieve data using livewire and blade in laravel

我正在为用户提供提交案件的一个特征,即可以将案件留给数据库处理,但我无法从数据库中检索。 这部法典。

1.manage-case.php content

<?php

namespace AppHttpLivewire;

use AppModelsCases;
use LivewireComponent;

class ManageCase extends Component
{
    public $cases;
    public $title;
    public $description;
    public $status;
    public $feedback;


    public function render()
    {
        // Load the Livewire view with the current user s cases
        return view( livewire.manage-case );
    }
    public function addCase()
    {
        
        $cases = new Cases();
        $cases->title = $this->title;
        $cases->description = $this->description;
        $cases->status =  pending ;
        $cases->feedback =  pending for admin reply ;
        $cases->id = auth()->user()->id;

        $cases->save();
        $this->resetFields();
        return redirect()->route( manage-case );
    }

    public function getUserCases()
    {
        // Retrieve cases belonging to the authenticated user
        $this->cases = Cases::where( id , auth()->user()->id)->get();
    }


    

    

    private function resetFields()
    {
        // Reset input fields to their default values
        $this->title =   ;
        $this->description =   ;
        $this->status =   ;
        $this->feedback =   ;
    }
}

2.manage-case.blade



<div class="flex">
    <div class="w-1/5">
        <ul class="list-none text-xl flex flex-col items-center rounded-lg bg-gray-200 p-4">
            <li class="mt-6 mb-6"><a href="" class="block hover:bg-gray-300 transition-colors duration-200 p-2 rounded-lg">Orders</a></li>
            <li class="mt-6 mb-6"><a href="{{route( manage-location )}}" class="block hover:bg-gray-300 transition-colors duration-200 p-2 rounded-lg">Addresses</a></li>
            <li class="mt-6 mb-6"><a href="#" class="block hover:bg-gray-300 transition-colors duration-200 p-2 rounded-lg">Insurance</a></li>
            <li class="mt-6 mb-6"><a href="#" class="block hover:bg-gray-300 transition-colors duration-200 p-2 rounded-lg">Review</a></li>
            <li class="mt-6 mb-6"><a href="{{route( manage-case )}}" class="block hover:bg-gray-300 transition-colors duration-200 p-2 rounded-lg">Cases</a></li>
        </ul>
        
    </div>
    <div class="w-4/5">
        <div>
            <label for="title" class="input-label w-32">Title</label><br>
            <input type="text" wire:model="title" class="input-field">
        </div>
        <div>
            <label for="description" class="input-label w-32">Description</label><br>
            <input type="text" wire:model= description  class="input-field rounded-sm">
        </div>
        <div>
            <button class="" wire:click= addCase >Submit</button>
        </div>
    
        
    </div>

    
    <div class="mt-10">
        <div class="flex flex-wrap">
            @if ($cases !== null && count($cases) > 0)
                @foreach ($cases as $case)
                    <div class="w-full md:w-1/2 lg:w-1/3 px-2 mb-4">
                        @livewire( retrieve-case , [ caseid  => $case->caseID], key($case->caseID))
                    </div>
                @endforeach
            @else
                <p>no record found</p>
            @endif
        </div>
    </div>
    
</div>

3.retrieve-case.php content

<?php

namespace AppHttpLivewire;

use LivewireComponent;
use AppModelsCases;


class RetrieveCase extends Component
{
    public $cases;
    public $caseID;
    public $title;
    public $description;
    public $status;
    public $id;

    public function mount($caseID){
        $this->cases = Cases::find($caseID);
        $this->caseID = $caseID;
        $this->title = $this->case->title;
        $this->description = $this->case->description;
        $this->status = $this->case->status;
        $this->id = $this->case->id;


    }

    
    public function render()
    {
        return view( livewire.retrieve-case );
    }

    public function deleteCase(){
        $this->cases->delete();
        $this->emit( caseDeleted );
    }

    public function getUserCases()
    {
        // Retrieve cases belonging to the authenticated user
        $this->cases = Cases::where( id , auth()->user()->id)->get();
    }


    
}

4.retrieve-case.blade/strong>

<!-- resources/views/livewire/retrieve-case.blade.php -->

<div>
    <h2>Case Details</h2>

    @if ($case)
        <ul>
            <li>
                <strong>Title:</strong> {{ $case->title }}<br>
                <strong>Description:</strong> {{ $case->description }}<br>
                <strong>Status:</strong> {{ $case->status }}<br>
                <strong>ID:</strong> {{ $case->id }}<br>

                <!-- Button to delete the case -->
                <button wire:click="deleteCase">Delete</button>
            </li>
        </ul>
    @else
        <p>No case found.</p>
    @endif
</div>

i) 尝试改变海滩通道,并仍然从事固定工作,即期望它能够检索已提交的案件,并使用海滩通道将其列入名单。

问题回答

引证。

浏览了数据。

1.manage-case.php构成部分

 public function render()
{
    // Load the Livewire view with the current user s cases
    $cases = Cases:all();
    return view( livewire.manage-case ,[ cases =>$cases]);
}




相关问题
Table of calificacions in php and laravel

I created a table in order to show the name of the students, name of the subjects and the grade of the subject of the student I have the next code: this is the index part <form action="{{ ...

How to fix CORS for Capacitor/Quasar App in a Laravel API

I have an App built on top of Quasar and Capacitor, with an API built on top of Laravel. Everything works well on the dev environment until I build and install the app on my phone, then I keep getting ...

Laravel +Vuejs CORS issue

I am facing a dilemma wit the CORS issue. I have application that is configured as follow: API: https://abc.mydomain.com (laravel) front end: https://subdomain.mydomain.com(VueJS) Both applications ...

Laravel wrong redirecting to login page after login

In a multi tenancy with subdomain enviroment (http://zapburger.dex.local) when user fills login form with valid data and make login, laravel redirect to dashboard route (as expected) and then redirect ...