javascript - react.js with laravel relationship


this error happend when I add company name to client

{} in view

Uncaught TypeError: Cannot read property 'name' of null

what can I do to solve this error

in CompanyController

public function index(request $request)

        $clients = $this->client->with('company')->orderBy('date_created','DESC');

            $clients = $clients->where(function($query) use($request){          
                $query->where('client_id', $request->search);
                $query->orWhere('first_name', 'LIKE', '%' . $request->search . '%');
        // applay pagination on clients list
        $clients = $clients->paginate(10);
        // get all clients 
        return response()->json($clients);

in view :

            loading : true,
            search    : '',
            page      : 1,
            total     : 0,
            pageCount : 0,
        this.handleChangeSearch   = this.handleChangeSearch.bind(this);
        this.handleSubmit         = this.handleSubmit.bind(this);
        this.handlePageChange     = this.handlePageChange.bind(this);

in render()

     {, i){
             <tr key={i}>
              <td><Link to={`/clients/${client.client_id}`}>{client.client_id}</Link></td>
              <td>{ }</td>
              <td>{client.email_address }</td>
              <td>{client.contact_phone }</td>
              <td>{client.date_created }</td>

People are also looking for solutions to the problem: php - Laravel dropzone problem for upload with product_id


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.