Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jcoder02k's avatar

Creating another View page

how exactly this work if you already have existing view?

if you register it to your getpages()

'view' => Pages\ViewCustomer::route('/{record}'), // existing view 'view-contact' => Pages\ViewCustomerContact::route('/{record}/contact'), // additional view

how will you make the page and link that page?

I have try several ways but no success, the documentation not that clear Tables\Actions\Action::make('contact')

0 likes
1 reply
LaryAI's avatar
Level 58

It seems like you're working with a web framework that allows you to define views and their corresponding routes. From the context, it looks like you might be using Laravel, or a similar MVC framework, and you're trying to add a new view for viewing a customer's contact information.

To create a new view and link to that page, you would typically follow these steps:

  1. Create the View File: First, you need to create the view file for the new page. This file should be placed in the appropriate directory within your resources/views folder (assuming you're using Laravel). For example, if you're creating a view for customer contacts, you might create a file named view_customer_contact.blade.php.

  2. Define the Route: Next, you need to define a route that will serve this view. In your web.php file (or wherever you define your routes), you would add a new route that points to a controller method that returns this view.

// web.php or routes file
Route::get('/customers/{record}/contact', 'CustomerController@viewContact')->name('view-contact');
  1. Create the Controller Method: In the CustomerController (or the relevant controller), you would add a method called viewContact that retrieves the necessary data and returns the view.
// CustomerController.php
public function viewContact($record)
{
    $customer = Customer::findOrFail($record);
    // Assuming you have a relationship set up to retrieve contact information
    $contact = $customer->contact;

    return view('view_customer_contact', compact('customer', 'contact'));
}
  1. Link to the New Page: To link to this new page, you would use the named route that you defined earlier. You can create a link in your existing views using the route helper function.
{{-- In your Blade template, for example in view_customer.blade.php --}}
<a href="{{ route('view-contact', ['record' => $customer->id]) }}">View Contact</a>
  1. Create the Action: If you're using a system that allows you to define actions like Tables\Actions\Action, you would create an action that redirects to the new route.
use Tables\Actions\Action;

Action::make('contact')
    ->label('View Contact')
    ->action(function ($record) {
        return redirect()->route('view-contact', ['record' => $record->id]);
    });

Make sure to replace Customer::findOrFail, CustomerController, and the view names with the actual names used in your application. Also, ensure that the relationships and data retrieval logic match your application's structure.

If you're not using Laravel, the general approach would still be similar: create the view, define the route, create the controller method, and then link to the page using the appropriate syntax for your framework.

Please or to participate in this conversation.