4 months ago

Can't save fetched login user name to relationship

Posted 4 months ago by hariprasatn

i creating a form to user once login, so they have to insert all in empty field except for the user name because i fetch from registered username. the database table for this from and registered user is different, so i create relationship for login user and this form. i don't know where is the error, with this code once i fill-up and submit the form it didn't show any error

my blade

<form method="POST" action="{{ route("admin.customers.store") }}" enctype="multipart/form-data">
    <h2 style="text-align: center"> User Details Form</h2> <br>
    <div class="row">
        <div class="col-md-6">
            <label for="name">{{ trans('cruds.customer.fields.user') }}</label>
            <input class="form-control select2" type="text" name="name" value="{{ auth()->user()->name }}">

        <div class="col-md-6 {{ $errors->has('company_name') ? 'has-error' : '' }}">
            <label class="required" for="company_name">{{ trans('cruds.customer.fields.company_name') }}</label>
            <input class="form-control" type="text" name="company_name" id="company_name" value="{{ old('company_name', '') }}" required>
                <span class="help-block" role="alert">{{ $errors->first('company_name') }}</span>
            <span class="help-block">{{ trans('cruds.customer.fields.company_name_helper') }}</span>


    public function store(StoreCustomerRequest $request)
        $customer = Customer::create($request->all());

        $attributes = request()->validate([
            'name' => 'required'
        return redirect()->route('admin.customers.index');


If i use the below code it works perfectly but the login user can select other users too, i dont want the login user preview or select other users name.

maybe if you can help me solve this part then the top part i no need to do.

<div class="form-group {{ $errors->has('user') ? 'has-error' : '' }}">
    <label for="user_id">{{ trans('cruds.customer.fields.user') }}</label>
    <select class="form-control select2" name="user_id" id="user_id">
        @foreach($users as $id => $user)
            <option value="{{ $id }}" {{ old('user_id') == $id ? 'selected' : '' }}>{{ $user }}</option>
        <span class="help-block" role="alert">{{ $errors->first('user_id') }}</span>
    <span class="help-block">{{ trans('cruds.customer.fields.user_helper') }}</span>

Please sign in or create an account to participate in this conversation.