Data listing with Laravel

Asked

Viewed 54 times

0

Good night devs!

I need some strength! Here’s the thing.

I am developing an application using the framework.

I have the following models: design and functionality

The business rule of the application is as follows, each project must have one or more functionalities and each functionality should belong to by a project, so I have the relationship 1:n, until then everything right, because I am able to perform the registration, editing, removal ,and the listing of projects and their respective functionalities.

However, I created a link in the list of projects called functionalities, and the idea is that when you click on this link (features) all the features related to a particular project are displayed, for example:

project1 (function A, functionality B) project2 (functionality c, functionality D)

However, that’s where I’m not succeeding, because when I click on the link (features) is displayed all the functionalities of all projects and want to be displayed only the functionalities related to a given project.

Follow the code you can already develop

listagem dos projetos

<div class="card">
        <table class="table table-hover">
            <tr>
                <th>ID</th>
                <th>PROJETO</th>
                <th>DESCRIÇÃO</th>
                <th>INICIO</th>
                <th>TÉRMINO</th>
                <th>SITUAÇÃO</th>
                <th>AÇÃO</th>
            </tr>
        @foreach ($listProj as $item)
            <tr>
                <td>{{$item->id_projetos}}</td>
                <td>{{$item->nome_projeto}}</td>
                <td>{{$item->descricao}}</td>
                <td>{{\Carbon\Carbon::parse($item->data_inicio)->format('d/m/Y')}}</td>
                <td>{{\Carbon\Carbon::parse($item->data_fim)->format('d/m/Y')}}</td>
                <td>{{$item->status_projeto}}</td>
                <td>
                    <a href="{{route('listFunc',['id_projetos'=>$item->id_projetos])}}" class="btn btn-sm btn-info">Funcionalidades</a>
                    <a href="{{route('editProj',['id_projetos'=>$item->id_projetos])}}" class="btn btn-sm btn-info">Editar</a>
                    <a href="{{route('delProj',['id_projetos'=>$item->id_projetos])}}"  class="btn btn-sm btn-danger" onclick="return confirm('DESEJA EXCLUIR O PROJETO ?')">Excluir</a>
                </td>
            </tr>
        @endforeach
        </table><br>
        {{$listProj->links()}} 
     </div>  


controller funcionalidade

class FuncionalidadeController extends Controller
{
//esse contrutor, tem como proposito redirecionar o usuario para pagina de login, se este não estiver logado e tentar acessar alguma aera do sistema
   
public function __construct(){
    $this->middleware('auth');
}

public function listFunc(){
    $listFunc = Funcionalidade::paginate(5);
    return view('AdminTarefaViews.listFunc',['listFunc'=>$listFunc]);
}



listagem de funcionaliade

<div class="card">
    <table class="table table-hover">
        <tr>
            <th>ID</th>
            <th>FUNCIONALIDADE</th>
            <th>INICIO</th>
            <th>TERMINO</th>
            <th>SITUAÇÃO</th>
            <th>PROJETO</th>
            <th>AÇÃO</th>
        </tr>
    @foreach ($listFunc as $item)
        <tr>
            <td>{{$item->id_funcionalidades}}</td>
            <td>{{$item->nome_funcionalidade}}</td>
            <td>{{\Carbon\Carbon::parse($item->data_inicio)->format('d/m/Y')}}</td>
            <td>{{\Carbon\Carbon::parse($item->data_fim)->format('d/m/Y')}}</td>
            <td>{{$item->status_funcionalidade}}</td>
            <td>{{$item->projeto->nome_projeto}}</td>
            <td>
                <a href="{{route('editFunc',['id_funcionalidades'=>$item->id_funcionalidades])}}" class="btn btn-sm btn-info">Editar</a>
                <a href="{{route('delFunc',['id_funcionalidades'=>$item->id_funcionalidades])}}" class="btn btn-sm btn-danger" onclick="return confirm('DESEJA EXCLUIR A TAREFA ?')">Excluir</a>
            </td>
        </tr>
    @endforeach
    </table><br>
</div>

1 answer

2


you have to use the id you have passed $item->id_projetos as a parameter for your list

public function listFunc($id_projetos){
    $listFunc = Funcionalidade::where('id_projeto', $id_projetos)->paginate(5);
    return view('AdminTarefaViews.listFunc',['listFunc'=>$listFunc]);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.