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

Kevintjuhz's avatar

Character Identifier returns null

The project I am a developer at a Fivem server where you can have a life you can be a criminal or even become a cop. For the police in the server I am making a system where they can see a persons his info. (the houses he owns, the cars he has, etc.)I am getting stuck at the point where the police can add a specification to that user(for example: if he is carrying weapons). When I try to send the identifier with the post, the identifier returns null. Photos and code will explain more.

Why it is a identifier is because Fivem works with steam id's.

what i want to achive: enter image description here

The logic down below

Getting all the users

in MeosController:

public function personen() {
    $characters = DB::table('characters')->paginate(20);
    return view('meos.personen', ['characters' => $characters]);
}

Character model:

class Character extends Model
{
    protected $table = 'characters';

    protected $primaryKey = 'identifier';

    public function properties() {
        return $this->hasMany('App\Property', 'owner');
    }

    public function fines() {
        return $this->hasMany('App\Fine', 'identifier');
    }

    public function license() {
        return $this->hasMany('App\License', 'owner');
    }

    public function gevaarsklasse() {
        return $this->hasMany('App\Gevaarsklasse', 'identifier');
    }

    public function arrestatiebevel() {
        return $this->hasMany('App\Arrestatiebevel', 'identifier');
    }
}

Routes:

Route::get('/personen', 'MeosController@personen')->name('personen');
Route::get('/personen_info/{identifier}', 'MeosController@personen_info')->name('personen_info');

The view:

@extends('layouts.master')

@section('content')
    <div class="row justify-content-center">
        <div class="col-md-12">

            {{ $characters->links() }}

            @include('includes.search-personen')

            <table class="table">
                <thead>
                    <tr>
                        <th scope="col"></th>
                        <th scope="col">Voornaam</th>
                        <th scope="col">Achternaam</th>
                        <th scope="col">Geboortedatum</th>
                        <th scope="col">Geslacht</th>
                        <th scope="col">Lengte</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($characters as $character)
                    <tr>
                        <td><a href="{{ route('personen_info', ['identifier' => $character->identifier]) }}">Meer</a></td>
                        <td>{{ $character->firstname }}</td>
                        <td>{{ $character->lastname }}</td>
                        <td>{{ $character->dateofbirth }}</td>
                        <td>{{ $character->sex }}</td>
                        <td>{{ $character->height }} CM</td>
                    </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>
@endsection

So this gets all the persons from database and when you click on 'Meer' than you wil see the persons his info. Like if he owns any apartments etc.

Users info Here lays the problem. It will get a lot of data from the user but on this page you will also be able to post stuff to his info.

Getting the info:

public function personen_info($identifier) {
    // Karakter informatie ophalen
    $character = Character::find($identifier);
    // Eigen appartementen ophalen
    $properties = Property::where('owner', $identifier)->get();
    // Boetes ophalen
    $fines = Fine::where('identifier', $identifier)->where('target', 'society_police')->get();
    // Licenties ophalen
    $licenses = License::where('owner', $identifier)->get();
    // Gevaarsklasse ophalen
    $gevaarsklasses = Gevaarsklasse::where('identifier', $identifier)->get();
    // Arrestatie Bevel ophalen
    $arrestatiebevelen = Arrestatiebevel::where('identifier', $identifier)->get();

    // Fetch into the view
    return view('meos.personen-info', [
        'character' => $character,
        'properties' => $properties,
        'fines' => $fines,
        'licenses' => $licenses,
        'gevaarsklasses' => $gevaarsklasses,
        'arrestatiebevelen' => $arrestatiebevelen,
    ]);
}

The blade where the problem is:

{{-- Gevaarsklasses toevoegen --}}
        <div class="card">
          <div class="card-header">
            Gevaarsklasse Toevoegen
          </div>
          <div class="card-body">
            @if ( count($gevaarsklasses) > 0)
            <table class="table">
              <thead>
                <tr>
                  <th scope="col">Gevaarsklasse</th>
                  <th scope="col"></th>
                </tr>
              </thead>
              <tbody>
                @foreach( $gevaarsklasses as $gevaarsklasse ) 
                <tr>
                  <td>{{ $gevaarsklasse->klasse }}</td>
                  <td><a href="{{ route('gevaarsklasse_verwijderen', ['id' => $gevaarsklasse->id]) }}">Verwijder</a></td>
                </tr>
                @endforeach
              </tbody>
            </table>
            <br>
            @endif
            <br><br>

            <h5>Gevaarsklasse toevoegen:</h5>
            <hr>

            {!! Form::open(['method'=>'POST','action'=> ['MeosController@PostGevaarsklasse', $character->identifier],'class'=>'navbar-form navbar-left'])  !!}

                <div class="form-group">
                    <label for="danger">Gevaarsklasse:</label>
                    <select class="form-control" name="danger" id="danger">
                        <option value="1">1. Alcoholist</option>
                        <option value="2">2. Verslaafd aan verdovende middelen</option>
                        <option value="3">3. Medische indicatie(overdosissen)</option>
                        <option value="4">4. Vuurwapengevaarlijk</option>
                        <option value="5">5. Wapengevaarlijk</option>
                        <option value="6">6. Geweldpleger</option>
                        <option value="7">7. Vluchtgevaarlijk</option>
                        <option value="8">8. Zelfmoordneigingen</option>
                    </select>
                </div>  
                {!! Form::token() !!}
                <button type="submit" class="btn btn-default">Toevoegen</button>
            {!! Form::close() !!}

          </div>
        </div>

It fetches all the gevaarsklasse info about that user (that stuff works) but I can't assign the identifier while posting.

Controller function for posting:

public function PostGevaarsklasse(Request $request, $identifier) {
    // $character = Character::where('identifier', $character->identifier);
    // dd($character);
    // Karakter informatie ophalen
    $random = $identifier;
    dd($random);
    $gevaarsklasse = new Gevaarsklasse();
    // $gevaarsklasse->identifier = $character;
    $gevaarsklasse->klasse = $request['danger'];
    $gevaarsklasse->save();

    return redirect()->back()->with('success', 'Gevaarsklasse succesvol toegevoegd');
}

Random returns null. Can't find out why.

This is the route:

Route::post('/personen_info/{identifier}/gevaarsklasse/post', 'MeosController@PostGevaarsklasse')->name('post.gevaarsklasse');

Picture of the view:

This is where everything happens for posting and fetching the gevaarsklasses.

0 likes
0 replies

Please or to participate in this conversation.