alierfani

alierfani

Member Since 3 Years Ago

Experience Points 3,650
Experience Level 1

1,350 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 0
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

01 Nov
3 years ago

alierfani started a new conversation L5.1 Jquery Ajax Code Sometimes Not Working

I'm using the following code to retrieve the city based on the selected province, but sometimes it does not work and gives this error:

XMLHttpRequest cannot load http://example.com/profile/cities/1. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.example.com' is therefore not allowed access.

My jQuery version is v1.11.3. What causes this?

//jQuery code

    $(document).ready(function(){
       var $province= $('#province');
        $province.on('change', function(){
            var $provinceValue=$province.find(':selected').val();
            var $requestURL='http://example.com/profile/cities/'+$provinceValue;
            $.getJSON($requestURL, function(data){
                $('#city').empty();
                $.each(data, function(i, city){
                    $('#city').append('<option value='+city.id+' >'+city.city+'</option>');
                });
            });
        });
    });


//Route
    Route::get('profile/cities/{province_id}','UserController@cities' );

    //Method
 public function cities($province_id)
    {
        $cities=City::where('province_id', $province_id)->get();
        return $cities;
    }

alierfani left a reply on L5.1 Database Queue Not Working

@usman Thanks. I will wait for the next release.

25 Oct
3 years ago

alierfani left a reply on $mailer->queue Throws Exception Trying To Get Property Of Non-object

I have the same problem. Please help us.

alierfani left a reply on L5.1 Database Queue Not Working

@mstnorris Thanks. I will follow that conversation.

alierfani started a new conversation L5.1 Database Queue Not Working

I'm trying to use database driver for queuing emails. Using Mail::send emails are sent as expected. But when I use Mail::queue the user object passed to the view gets null "Trying to get property of non-object".

I have a mailer class and these are the methods responsible for sending the email:

 public function sendAssignmentEmail(User $user)
    {
        $this->to=$translator->email;
        $this->view='emails.assigned';
        $this->data=compact('user');
        $this->subject='subject';
        $this->deliver();
    }

public function deliver()
    {
        $to=$this->to;
        $subject=$this->subject;
        $from=$this->from;
        return $this->mailer->queue($this->view,$this->data, function($message)
        use($to, $subject, $from)
        {
            $message->from($from, 'example.com');
            $message->to($to);
            $message->subject($subject);
        });
    }

What am I doing wrong?

15 Oct
3 years ago

alierfani left a reply on L5.1 How To Find And Show Database Records In Admin Area?

@pmall Thanks, it worked but the URL is kind of messy:

admin/projects/%7Bproject_id%7D?project_id=5

What is the problem?

alierfani left a reply on L5.1 How To Find And Show Database Records In Admin Area?

@pmall Could you please tell me what should be like the form with get method?

{!! Form::open(['action' => 'AdminController@showProject', 'method' => 'get']) !!}
    {!! Form::label('project_id', 'Project Id', ['class' => 'control-label']) !!}
        {!! Form::text('project_id', null, ['class' => 'form-control']) !!}
    {!! Form::submit('Submit', ['class' => 'form-control']) !!}
    {!! Form::close() !!}

And what about the routes? I have defined the following:

Route::get('admin/projects/{project_id}', 'AdminController@showProject');

alierfani left a reply on L5.1 How To Find And Show Database Records In Admin Area?

@ohffs Yes I mean the id of a project. The result should return only one record. There may be lots of projects in database.

alierfani started a new conversation L5.1 How To Find And Show Database Records In Admin Area?

In the admin area of my app, I want to have a form by which an admin can find a project by its id and show the project details there. What is the best approach to implement this?

14 Oct
3 years ago

alierfani left a reply on L5.1: How To Deploy To Shared Hosting Properly?

@ShaunL There are other blogs hosted on this service, so I need to create an addon domain. Anyway, I found the solution after some searching around . I modified the document root for this domain and changed to /motarjeman/public . This was the easiest and best solution. Thank you @Snapey @davidrushton and @jlrdw for your help.

13 Oct
3 years ago

alierfani started a new conversation L5.1: Assets Will Not Load After Deploying To Shared Hosting

I have deployed my Laravel 5.1 app to a shared hosting. I have created an addon domain using Cpanel. So I have a folder named "motarjeman" in public_html for this domain. Then I have uploded my project to this folder. All of my project files are in folder again called "motarjeman". Then I copied all contents of the public folder to the /public_html/motarjeman. At last I have modified the index.php in the root directory (i.e in the /public_html/motarjeman) as following:

require __DIR__.'/motarjeman/bootstrap/autoload.php';
$app = require_once __DIR__.'/motarjeman/bootstrap/app.php';

Now the css and js is off in all views. How can I fix this?

12 Oct
3 years ago

alierfani left a reply on L5.1 How To Translate Attribute Values In The Form Validation Messages?

@pmall Thanks, there was an extra space after the 'username' attribute.

alierfani started a new conversation L5.1 How To Translate Attribute Values In The Form Validation Messages?

I need to translate the attribute values for the form validations. So I have duplicated the English validation errors and translated them to Farsi. Everything works but the attribute values are still in English. I thought I need to put the translation of attributes in the attributes array in the validation file as follows, but it's not working.

 'attributes' => [
        'username '=>'نام کاربری'
    ],

How can I translate them?

11 Oct
3 years ago

alierfani started a new conversation L5.1: How To Share A Collection In All Views?

I need to share a collection in all of my views. This collection contain the website news:

$news=NewsStory::orderBy('created_at', 'desc')->paginate(5);

How can I do this?

09 Oct
3 years ago

alierfani left a reply on L5 Forms: Route Not Defined Error

@bestmomo Thanks a lot. As you guessed, there was another call to this route which did not exist.

alierfani started a new conversation L5 Forms: Route Not Defined Error

I have defined a resourceful route like this:

Route::resource('user/info/experience', 'ExperienceController'); And the following is what i have used in my form:

{!! Form::open([
                 'route'=>'user.info.experience.store',
                 'method' => 'post',               
                ]
) !!}

Now it's giving me the

Route [user.info.experience] not defined

What am I doing wrong?

29 Sep
3 years ago

alierfani left a reply on Laravel 5.1 The Last() Method Not Working

@thomaskim Thanks a lot. I prefered @Rtransat suggestion.

alierfani left a reply on Laravel 5.1 The Last() Method Not Working

@ Rtransat @bestmomo @phildawson @pmall Thank you all for your suggestions. All of them can work. I used the following approach:

$last_project=Project::where('user_id','=',auth()->user()->id)->get()->last();

@phildawson auth()->id is not working for me!

alierfani started a new conversation Laravel 5.1 The Last() Method Not Working

I'm trying to fetch the last record in a collection but the last() method gives me "BadMethodCallException" error. What is the problem?

        $last_project=Project::where('user_id','=',auth()->user()->id)->last();
27 Sep
3 years ago

alierfani left a reply on How To Retrieve A Collection Based On Some Conditions?

I found a solution. I defined the following scope in the Project model:

public function scopeLangMatch($query, $from1,$from2,$from3,$from4, $to1, $to2, $to3, $to4)
    {
        $match=[
            'source_lang_id'=>$from1,
            'target_lang_id'=>$to1
        ];
        $match2=[
            'source_lang_id'=>$from2,
            'target_lang_id'=>$to2
        ];
        $match3=[
            'source_lang_id'=>$from3,
            'target_lang_id'=>$to3
        ];
        $match4=[
            'source_lang_id'=>$from4,
            'target_lang_id'=>$to4
        ];
        return $query->where($match)->orWhere($match2)->orWhere($match3)->orWhere($match4);
    }

Let me know if there is any better approach.

alierfani started a new conversation How To Retrieve A Collection Based On Some Conditions?

I need to filter a collection of projects based on some conditions. Hear is the scenario.

//This is part of projects table schema
  Schema::create('projects', function (Blueprint $table) {
           ...
            $table->smallInteger('source_lang_id')->index()->unsigned();
            $table->smallInteger('target_lang_id')->index()->unsigned();
           ...
        });
//This is part of translator_infos schema
Schema::create('translator_infos', function (Blueprint $table) {
          ....
            $table->smallInteger('from_l_1_id')->index()->unsigned();
            $table->smallInteger('from_l_2_id')->index()->nullable()->unsigned();
            $table->smallInteger('from_l_3_id')->index()->nullable()->unsigned();
            $table->smallInteger('from_l_4_id')->index()->nullable()->unsigned();
            $table->smallInteger('to_l_1_id')->index()->unsigned();
            $table->smallInteger('to_l_2_id')->index()->nullable()->unsigned();
            $table->smallInteger('to_l_3_id')->index()->nullable()->unsigned();
            $table->smallInteger('to_l_4_id')->index()->nullable()->unsigned();
        ....
        });

So each project has a source and target language. Translators may have 4 language pairs. What I need is that to filter the collection of projects and find projects that their source and target language match at least one of the translator language pairs and pass this collection to the view. For now the query I'm using is the following:

        $projects=Project::orderBy('created_at', 'desc')->where('status_id', "=", 1)->paginate(15);

How can I add this condition to the query?

24 Sep
3 years ago

alierfani left a reply on How To Insert Multiple Equal Records Into Database From Multiple Form Inputs?

@belisar It gives the error after submitting the form. Without form helpers there is a risk of sql injection. Anyway, I decided to change my schema.

23 Sep
3 years ago

alierfani left a reply on How To Insert Multiple Equal Records Into Database From Multiple Form Inputs?

@belisar Thank you. But if I use [] for a text field it will result in "htmlentities() expects parameter 1 to be string, array given" error.

alierfani started a new conversation How To Insert Multiple Equal Records Into Database From Multiple Form Inputs?

I have the following schema for users education:

Schema::create('educations', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->index()->unsigned();
            $table->string('study_field');
            $table->string('education_level');
            $table->string('location');
            $table->timestamp('start');
            $table->timestamp('end');
            $table->timestamps();
        });

So in the corresponding form I need 4 or 5 set of input fields like this:

<div class="row">
                <section class="col-md-6">
                    {!! Form::label('education_level', 'education level', ['class' => 'control-label']) !!}
                    <div class="input-group">
                        <div class="input-group-addon">
                                <span class="glyphicon glyphicon-education"></span>
                        </div>
                    {!! Form::select('education_level', $levels , null , ['class' => 'form-control']) !!}
                    </div>
                </section>
                <section class="col-md-6">
                    {!! Form::label('study_field', 'study field', ['class' => 'control-label']) !!}
                    <div class="input-group">
                        <div class="input-group-addon">
                            <span class="glyphicon glyphicon-education"></span>
                        </div>
                        {!! Form::text('study_field', null, ['class' => 'form-control']) !!}
                    </div>
                </section>
            </div>
            <div class="row">
                    <section class="col-md-6">
                        {!! Form::label('location', 'location', ['class' => 'control-label']) !!}
                        {!! Form::text('location', null, ['class' => 'form-control']) !!}
                    </section>
                    <section class="col-md-3">
                        {!! Form::label('start', 'start, ['class' => 'control-label']) !!}
                        {!! Form::selectYear('start', $year, $year-40 ,null, ['class' => 'form-control']) !!}
                    </section>
                    <section class="col-md-3">
                        {!! Form::label('end', 'endل', ['class' => 'control-label']) !!}
                        {!! Form::selectYear('end', $year , $year-40 ,null, ['class' => 'form-control']) !!}
                    </section>
                </div>

The first set of these input fields will be required and the other sets will be optional. How can I implement this?

15 Sep
3 years ago

alierfani left a reply on L5 Creating Custom Validation Rules

The problem was with my pattern. It should be like this:

Validator::extend('valid_username', function ($attribute, $value, $parameters)
            {
                    return preg_match('/^[a-zA-Z0-9_\-\.]+$/', $value);
            }

alierfani started a new conversation L5 Creating Custom Validation Rules

In a registration form I the username should only contain a-z A-Z 0-9 underscore, dashes, and dots. So I have defined a custom validator in the boot method of AppServiceProvider as follows;

Validator::extend('valid_username', function ($attribute, $value, $parameters)
            {
                    return preg_match('[a-zA-Z0-9_\-\.]', $value);
            }

But the validation never passes. what I'm doing wrong?

alierfani left a reply on Laravel 5.1 Change Password Functionality

Thanks a lot @thomaskim . It worked perfectly.

alierfani started a new conversation Laravel 5.1 Change Password Functionality

I need a change password functionality for my laravel app. I have created this view:

{!! Form::password('old_password', ['class'=>'form-control']) !!}
{!! Form::password('password', ['class'=>'form-control']) !!}
{!! Form::password('password_confirmation', ['class'=>'form-control']) !!}

Then in my controller I'm checking to see if the value entered for the old_passwordis the same as user's current password.

if(bcrypt($request->old_password) !=$user->password) return redirect()->back()

The problem is that the above condition will always be true. This mins even if the user enters a valid password this condition will return true! Why it is so? By the way I'm hashing the password in my user model:

 public function setPasswordAttribute($password){
        $this->attributes['password'] = bcrypt($password);
    }  
09 Sep
3 years ago

alierfani left a reply on What Is The Best Setup For A Subscription System?

@Mike Hopley Thanks a lot. It helped me much.

alierfani left a reply on What Is The Best Setup For A Subscription System?

@DanSmith @mcprogramming Thank you. My app will use the Iranian bank system. I wish I could use Laravel Spark but its not suitable for my purpose.

Can you just suggest the proper setup for the database tables?

alierfani started a new conversation What Is The Best Setup For A Subscription System?

I need a subscription system for my app with some subscription plans. Can anyone tell what is the best database setup for such system? What tables are need and what columns?

07 Sep
3 years ago

alierfani left a reply on L5.1 How To Pass The Id Of An Object To Another View To Be Used As The Foreign Key In Another Table?

I found a solution which worked.In the show method of projects controller I used the put() method to flash the project->id to the session:

$request->session()->put('project_id', $project->id);

then in the create method of quotes controller I used the pull() method to get the project_id out of session.

$id=$request->session()->pull('project_id');

But there was a little problem with this approach, and in case the user decides to refresh the form page there will be no project_id key in session. To tackle this I decided to redirect the user to the list of projects to select one again.

alierfani left a reply on L5.1 How To Pass The Id Of An Object To Another View To Be Used As The Foreign Key In Another Table?

@starbolt No, I'm not loading a view with the project data. In the first page I'm loading the project data with a link to the create quote page on which I only need the project id to be inserted into quotes table in project_id column.

06 Sep
3 years ago

alierfani started a new conversation L5.1 How To Pass The Id Of An Object To Another View To Be Used As The Foreign Key In Another Table?

I have a projects table and a quotes table with the following structure:

 Schema::create('quotes', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('translator_id')->index()->unsigned();
           $table->integer('project_id')->index()->unsigned();
            $table->decimal('quote', 10,0);
            $table->timestamps();

On the project page I need a link which refers to the page for creating a new quote. How can I pass the id of a project to the create view of a quote?

05 Sep
3 years ago

alierfani started a new conversation L5: How To Update The Value Of A Select Option Field Based On The Selected Item In Another Select Option Field?

I have tow select option field in a from, one for the province and one for the city. There are two tables which corresponds to this fields.

//The province table schema 
Schema::create('provinces', function (Blueprint $table) {
            $table->increments('id');
            $table->string('province', 100);
            $table->timestamps();
//The city table schema
Schema::create('cities', function (Blueprint $table) {
            $table->increments('id');
            $table->string('city', 20);
            $table->smallInteger('province_id')->unsigned();
            $table->index('province_id');
            $table->timestamps();

These tables are pre-populated with the name of provinces, cities and their related province id. In my form I need that after selecting a province, the city field be updated with a list of that province cities. How can I do this?

//The create method in controller
 public function create()
    {
        $provinces=Province::lists('province', 'id')->all();
        $cities=City::lists('city', 'id');
        return view('profile.create', compact('provinces', 'cities'));
    }
03 Sep
3 years ago

alierfani left a reply on How To Map An Array Of Ids Onto Their Corresponding Values In Another Table?

@bestmomo I found the problem. I was missing the 'return' in User model in subjects method ;)

alierfani left a reply on How To Map An Array Of Ids Onto Their Corresponding Values In Another Table?

@bestmomo I took your suggestion but it gives me "Call to a member function attach() on null" while the $subjects array is not "null". what is the problem?

$subjects=$request->get('subjects');
$user=User::find($request->user()->id);
$user->subjects()->attach($subjects);
02 Sep
3 years ago

alierfani left a reply on How To Map An Array Of Ids Onto Their Corresponding Values In Another Table?

@bestmomo @jekinney @tangoG Thank you all. After creating the subject_user pivot table and establishing the many to many relationship, how can I populate this table in the store method of my controller? I know that in the controller I have access to the array of selected subjects:

//array of subjects
$subjects=$request->get('subjects')

alierfani started a new conversation How To Map An Array Of Ids Onto Their Corresponding Values In Another Table?

I have a table column which holds an array of subject ids selected by the user. There is another table for these subjects and their values. I need to return the values corresponding to the ids saved in the subjects column. To make it more clear suppose that a user have chosen 5 subjects out of 34 subjects and the corresponding ids are saved in the subjects column as a string like this: 2,5,11,21,23 Each of these numbers corresponds to the id of a subject in the subjects table.

//This is the subjects table
public function up()
    {
        Schema::create('subjects', function (Blueprint $table) {
            $table->increments('id');
            $table->string('subject', 20);
            $table->timestamps();
        });
    }
//and this is the user_info table
 public function up()
    {
        Schema::create('user_info', function (Blueprint $table) {
    ...
    $table->string('translation_subjects');
    ...
     });
    }

How can I return an array of subject values to a view? I'm using Laravel 5.1

alierfani left a reply on How To Validate That At Least One Checkbox Is Checked In A Form Request?

@bobbybouwmann Thanks a lot. I don't know why the required rule wasn't working before!

alierfani started a new conversation How To Validate That At Least One Checkbox Is Checked In A Form Request?

I have a form in which the user should at least select one of the check boxes. This is the code for generating a group of check boxes in the view:

<div class="form-group">
          @foreach($subjects as $subject)
            <label>{!! Form::checkbox('subject[]', $i++, null,  ['id' => 'subject']) !!} {!! $subject !!} </label>
                @if($i%10==0)
                   {!! "<br />" !!}
                @endif
          @endforeach

    </div>

For now if the user does not select a subject the subject index will not set so there will be nothing to be validated. How can I validate that the user has selected at least one subject?

alierfani left a reply on How To Save Array Value To The Database Instead Of Array Key From A Select Option Input?

@jasonlewis What about using array_combine. Is it a good solution?

$options = ['a', 'b', 'c'];
$options = array_combine($options, $options);
01 Sep
3 years ago

alierfani started a new conversation How To Save Array Value To The Database Instead Of Array Key From A Select Option Input?

In my controller I have an array of options ($options=['a','b','c']) which I am using it in my view in a select input field. I need the values 'a','b','c' to be saved in the database instead of their corresponding keys (0,1,2). How can I do this?

alierfani left a reply on How To Add A Default Blank Option To A Select Input Field?

@bobbybouwmann Thanks a lot. Also it works with toArray().

$languages=Language::lists('fa_name', 'id')->all();

alierfani left a reply on How To Add A Default Blank Option To A Select Input Field?

@bobbybouwmann Again the same error! I think it's because the $languages is not an array, it's a colletion!

alierfani left a reply on How To Add A Default Blank Option To A Select Input Field?

@bobbybouwmann Thank you but this gives me a "Unsupported operand types" error.