Laravel Problem with passing parameters to Controllers

Asked

Viewed 461 times

0

then I have a pertinent problem. I need to create a link to the.Edit controller to edit of course a value in the database. I’ve tried pretty much everything. But I keep getting an error:

htmlspecialchars() expects Parameter 1 to be string, array Given (View: /var/www/html/project/Resources/views/student.blade.php)

I am currently using Forms&html from Laravel and have opened a form from Pointing Pro Edit:

{!! Form::open(['route'=>['aluno.edit', $aluno->id],'method'=> 'get']) !!}
      {!! Form::submit('Editar',['class'=>'btn btn-danger', 'id'=>'bt'])!!}
      {!! Form::close() !!}

My controller:

public function edit($id){
$aluno = $this->aluno->find($id);
return view('aluno', compact('aluno'));

}

In my student view.blade.php:

 @if (isset($aluno))
          {!! Form::model($aluno,['route'=>['aluno.update',$aluno->id],'class'=>'form-horizontal m-t-20','method'=>'PUT']) !!}
        @else
          {!! Form::open(['route'=>['aluno.store'],'method'=>'post','class'=>'form-horizontal m-t-20']) !!}
        @endif

I’ve tried to go through link:

<a href="{{route('aluno.edit',$aluno->id)}}" class="edit actions "><span></span> </a>

I always get the same error saying that a string was expected and pass an array

Use the same for the Destroy method and works perfectly:

{!! Form::open(['route'=>['aluno.destroy', $aluno->id], 'method'=> 'DELETE']) !!}
      {!! Form::submit('Apagar',['class'=>'btn btn-danger', 'id'=>'bt'])!!}
      {!! Form::close() !!}

I am doing some tests, it seems that this error is coming due to the Forms, I pointed to another controller ex:

 {!! Form::open(['route'=>['instrutor.edit', $aluno->id],'method'=> 'get']) !!}
      {!! Form::submit('Editar',['class'=>'btn btn-danger', 'id'=>'bt'])!!}
      {!! Form::close() !!}

And opened normally so follow my student view

New Student

      <div class="">
        @if (isset($aluno))
          {!! Form::model($aluno,['route'=>['aluno.update',$aluno->id],'class'=>'form-horizontal m-t-20','method'=>'PUT']) !!}
        @else
          {!! Form::open(['route'=>['aluno.store'],'method'=>'post','class'=>'form-horizontal m-t-20']) !!}
        @endif


          @if (isset($errors) && count($errors)>0)
              <div class="alert alert-danger">
                  @foreach ($errors->all() as $error)
                      <p> {{$error}} </p>
                  @endforeach
              </div>
          @endif

          <div class="form-group">
            {!! Form::label('nome', 'Nome', ['class' => 'control-label','for'=>'nome']) !!}
            {!! Form::text('nome',"",['class'=>'form-control','required','id'=>'nome']) !!}
          </div>

          <div class="form-group">
            {!! Form::label('cpf','CPF',['class'=>'control-label','for'=>'cpf']) !!}
            {!! Form::text('cpf',"",['class'=>'form-control','required','id'=>'cpf']) !!}
          </div>
          <div class="form-group">
            {!! Form::label('email','Email',['class'=>'control-label','for'=>'email']) !!}
            {!! Form::email('email',"",['class'=>'form-control','required','id'=>'email']) !!}
          </div>

          <div class="form-group">
            {!! Form::label('data_nascimento','Data de Nascimento',['class'=>'control-label','for'=>'data_nascimento']) !!}
            {!! Form::date('data_nascimento',"",['class'=>'form-control','required','id'=>'data_nascimento']) !!}
          </div>

          <div class="form-group">
            {!! Form::label('telefone','Telefone',['class'=>'control-label','for'=>'telefone']) !!}
            {!! Form::text('telefone',"",['class'=>'form-control','id'=>'telefone']) !!}
          </div>

          <div class="form-group">
            {!! Form::label('celular','Celular',['class'=>'control-label','for'=>'celular']) !!}
            {!! Form::text('celular',"",['class'=>'form-control','required','id'=>'celular']) !!}
          </div>

          <div class="form-group">
            {!! Form::label('cep','Cep',['class'=>'control-label','for'=>'cep']) !!}
            {!! Form::text('cep',"",['class'=>'form-control','required','id'=>'cep']) !!}
          </div>

          <div class="form-group">
            {!! Form::label('estados','Estado',['class'=>'control-label','for'=>'estados']) !!}
            {!! Form::text('estados',"",['class'=>'form-control','required','id'=>'estados']) !!}
          </div>

          <div class="form-group">
            {!! Form::label('cidade','Cidade',['class'=>'control-label','for'=>'cidaade']) !!}
            {!! Form::text('cidade',"",['class'=>'form-control','required','id'=>'cidade']) !!}
          </div>

          <div class="form-group">
            {!! Form::label('bairro','Bairro',['class'=>'control-label','for'=>'bairro']) !!}
            {!! Form::text('bairro',"",['class'=>'form-control','required','id'=>'bairro']) !!}
          </div>

          <div class="form-group">
            {!! Form::label('rua','Rua',['class'=>'control-label','for'=>'rua']) !!}
            {!! Form::text('rua',"",['class'=>'form-control','required','id'=>'rua']) !!}

            {!! Form::label('numero','Número',['class'=>'control-label','for'=>'numero']) !!}
            {!! Form::text('numero',"",['class'=>'form-control','required','id'=>'numero']) !!}
          </div>

          <div class="form-group">
            {!! Form::label('dataini','Data Matricula',['class'=>'control-label','for'=>'dataini']) !!}
            {!! Form::date('dataini',"",['class'=>'form-control','required','id'=>'dataini']) !!}
          </div>

          <div class="form-group text-right m-t-20">
            <div class="col-xs-12">
              @if (isset($aluno))
                {!! Form::submit('Editar',['route'=>['aluno.edit',$aluno->id] ,'class'=>'btn btn-danger', 'id'=>'btn']) !!}
              @else
                {!! Form::submit('Cadastrar',['route'=>'aluno.store','class'=>'btn btn-primary btn-just-icon', 'id'=>'btn']) !!}
              @endif
                {!! Form::reset('Limpar',['class'=>'btn btn-default btn-just-icon', 'id'=>'bt']) !!}
            </div>
          </div>
        {!! Form::close() !!}
      </div>
    </div>
  </div>
</div>

@endsection

  • Have you tried using ['route'=>['student.Edit', $student->id], 'method'=> 'PUT']? In your controller the route must accept the PUT method as well.

  • Yes when I change the Method without getting get this message: Methodnotallowedhttpexception

  • This error must be because in your controller the Edit method is mapped as GET. you can switch to PUT to do the test?

  • Look, I’m afraid n is possible, or so I have no idea how it does My controller is of the type Resource it already comes with these pre-established methods

  • Like this your route?

  • Route::Resource('/instructor', 'Instructorcontroller'); Route::Resource('/learner', 'Alunocontroller'); Route::Resource('/modality', 'Modalityecontroller'); Route::Resource('/lesson', 'Aulacontroller');

Show 1 more comment
No answers

Browser other questions tagged

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