dimanche 1 novembre 2015

Cannot show values when editing restful form in laravel 5

When editing form in laravel I cannot view the values being passed on the form. When i inputted values it successfully added to the table. However when I want to edit the values, they are not visible. However when I call the value outside the inputs form I can view the value.

See my code below.Can someone please help me. Thank you.

       create.blade.php
       <div class="panel-heading">
                    <h3 class="panel-title">New Report Form</h3>
                </div>
                <div class="panel-body">
                    @include('errors.list')
                    @include('partials.success')
                    {!!    Form::open(['route'=>'crime_reports.store','class'=>'form-horizontal']) !!}

                         @include('crimereports._form')

                    <div class="form-group">
                        <div class="col-md-7 col-md-offset-3">
                            {!! Form::submit('Save Changes', ['class'=>'btn btn-primary btn-md']) !!}
                            <i class="fa fa-save"></i>&nbsp;
                        </div>
                    </div>

                    {!! Form::close() !!}
                </div>
                <div class="panel-footer ">
                    <p><small>Crime Chase</small></p>
                </div>

edit.php

                {!! Form::model('$crime_edit',['method' => 'PATCH','route'=>['crime_reports.update',$crime_edit->id],
                    'class'=>'form-horizontal']) !!}

                @include('crimereports._form')

                <div class="form-group">
                    <div class="col-md-7 col-md-offset-3">
                        {!! Form::submit('Update Form', ['class'=>'btn btn-primary btn-md']) !!}
                    </div>
                </div>

                {!! Form::close() !!}

            </div>
            <div class="panel-footer ">
                <p><small>Crime Chase</small></p>
            </div>

crimereportcontroller

        public function store(CrimeNewReportRequest $request)
{
    $input = $request->all();

    CrimeReport::create($input);
   // $input = CrimeReport::create($request->all());

   // return redirect('crime_reports')->withSuccess("Fields were inserted!");
    return redirect()->back();
}  
      public function edit($id)
{
    $crime_edit = CrimeReport::findOrFail($id);

    return view('crimereports.edit',compact('crime_edit',$crime_edit));
}  

_form

   <div class="form-group">
    {!! Form::label('crime_victim', 'Victim Name',['class'=>'col-md-3 control-     label']) !!}
 <div class="col-md-8">
     {!! Form::text('crime_victim', null, ['class' => 'form-control', 
        'placeholder' => 'Enter Victim name']) !!}      
</div>

   <div class="form-group">
     {!! Form::label('crime_suspect', 'Suspect Name',['class'=>'col-md-3 control-label']) !!}

<div class="col-md-8">
     {!! Form::text('crime_suspect', null, ['class' => 'form-control', 
        'placeholder' => 'Enter Suspect Name']) !!}       
</div>

      <div class="form-group">
    {!! Form::label('suspect_description','List Description' ,['class'=>'col-md-3 control-label']) !!}
<div class="col-md-8">

     {!! Form::textarea('suspect_description', null, ['class'=>'form-control',
        'placeholder'=>'Details about suspect']) !!}
</div>



via Chebli Mohamed

Inserting excel data into database

I'm using Maatwebsite laravel-excel package to read my excel file.
And the code below shows how I'm trying to insert the data into my database.

First I post my file from my view:
{!! Form::open(array('url' => route('teste'))) !!}
    {!! Form::file('filename')!!}
    {!! Form::submit('Importar') !!}                
{!! Form::close() !!}

Then I use a route to redirect me to my Controller's method:
public function importData(Request $request){

    Excel::load($request->input('filename'), function($reader) {
       $reader->ignoreEmpty();
       $results = $reader->get()->toArray();
       foreach($results as $key => $value){
          $turma = new import_temp;
          $turma->cod_disciplina = $value['cod_disciplina'];
          $turma->nome_disciplina = $value['nome_disciplina'];
          $turma->cod_turma = $value['cod_turma'];  
           //....
            }
        })->get();
    }
}

I have three questions:

1) Is there a cleaner/better way to pass the name of the file ? As that's all I need to read it;
2) As you can see by my foreach, I have to write every single field of my table with the model instance $turma. Is there a better way to insert this kind of data?
3) Also, my IDE gives me a warning about the way I'm assign the data: model->field:

Referenced field is not found in subject class



via Chebli Mohamed

How do you obtain the user's ip address for the google reCAPTCHA request? PHP Laravel 5

I have implemented the Google ReCaptcha where it verifies just the g-captcha-response from the $_POST and my secret. However, I don't know how to obtain or send the remote ip. I'm using Laravel 5 and I'm new to php in general. Any help would be much appreciated :)



via Chebli Mohamed

Laravel SSL Protocol Error

I've purchased a test SSL certificate while my client acquires the EV one and I've set it up with a Laravel 5.1 project. I've forced the site to use https:// all the time using .htaccess but once in a while the entire site breaks and becomes unusable after this error:

"The operation couldn't be completed. Protocol Error." NSPOSIXErrorDomain:100

Other people are getting this issue with Laravel projects, however I haven't been able to find a stable solution.

http://ift.tt/1Q00x0k

This only happens in Safari under iOS and OSX. The problem is that Safari isn't able to recover from this issue at all only by clearing browsing cache and cookies.

I'd need help with this because I lose every single visitor on the site after a few minutes who uses Safari on iOS or OSX.

Thanks, Andre



via Chebli Mohamed

should we handle all things via plugins and components in october cms?

I am new to october cms. i learned somethings about themes and pages and ... .

i use rainlab blog plugin.

i want to show author section in post page. now i am using this function in php section to display user post, title, publish date,... .

//pages/post.php
<?php
     function onEnd(){
        $this['post'] = $this->post; //for access to {{ post.variables }} in template
     }
?>

and i display post details: {{ post.title }}, {{ post.user.first_name}}.

  1. should i make a plugin or top way is true?

  2. when should we make plugin?

  3. is there a faster and true way instead of plugins?


via Chebli Mohamed

Laravel routing form with method get

I'm using Laravel 5.1 and I have a problem with the routing. Currently, I have this on my routes.php

Route::get('/', 'ArticleSiteController@index');
Route::get('article/{url}', 'ArticleController@show');
Route::get('article/search/{text}', 'ArticleController@search');
Route::get('/{url}', 'PageController@index');

Routes are being redirected properly except for the search wherein it always use the ArticleController@show route.

On the homepage, I have a search form.

<form class="form-horizontal" action="http://ift.tt/1M4RmFP" method="GET">
    <input type="text" name="txtSearch" class="form-control" placeholder="Search for...">
    <span class="input-group-btn">
        <button class="btn btn-primary" type="submit">Go!</button>
    </span>
</form>

It redirects to this url: http://ift.tt/1Q3PjqK (which is correct) but uses the ArticleController@show method instead of the ArticleController@search.



via Chebli Mohamed

Laravel eloquent model save error

I am getting an error when trying to save my eloquent model as follows: Argument 1 passed to Illuminate\Database\Eloquent\Relations\HasOneOrMany::save() must be an instance of Illuminate\Database\Eloquent\Model, string given,

I have a model Question it hasMany AnswerOption on the other side AnswerOption belongsTo Question

I have a model QuestionRevision it hasMany QuestionRevisionAnswerOption on the other side QuestionRevisionAnswerOption belongsto QuestionRevision

Basically I want to copy the AnswerOptions from a Question I have retrieved to a new instance of QuestionRevision (as QuestionRevisionAnswerOptions).

I have saved a new QuestionRevision ($origRev) successfully. Now I am trying to add the QuestionRevisionAnswerOptions that go with it. This is where I get the error Argument 1 passed to Illuminate\Database\Eloquent\Relations\HasOneOrMany::save() must be an instance of Illuminate\Database\Eloquent\Model, string given,

I have tried saving the QuestionRevisionAnswerOptions all at once as an array using saveMany and also individually but I get the same error either way.

Here is the relevant code:

$original = Question::findOrFail($qId);  // find the original question
$origRev = new QuestionRevision();
// copy some stuff from original to origRev
$origRev->save();  // works to here

// now get the answerOptions from original and copy to $origRev
foreach ($original->answerOptions as $ao)
{
    $answerOption = new QuestionRevisionAnswerOption(['answer_text'=> $ao->answer_text,
                                                 'answer_explanation'   => $ao->answer_explanation,
                                                  'answer_option_id'     => $ao->id,
                                                  'is_correct'           => $ao->is_correct
                                                 ]);


    $origRev->revisionAnswerOptions()->save($answerOption); //This is the line that generates the error.
}

Why am I getting this error and how can I correct it?



via Chebli Mohamed