irankhosravi

Experience

3,170

0 Best Reply Awards

  • Member Since 7 Months Ago
  • 1 Lesson Completed
  • 0 Favorites

20th July, 2018

irankhosravi left a reply on How To Store Checkbox Values If Check Box Is In Foreach Loop (laravel) • 1 day ago

I want to change php (a example) to laravel.

irankhosravi left a reply on How To Store Checkbox Values If Check Box Is In Foreach Loop (laravel) • 1 day ago

My field is title in database and my checkbox name is infraction_id[{{ $infraction->id }}].

19th July, 2018

irankhosravi left a reply on How To Store Checkbox Values If Check Box Is In Foreach Loop (laravel) • 2 days ago

I searched but did not find anything.

irankhosravi started a new conversation How To Store Checkbox Values If Check Box Is In Foreach Loop (laravel) • 2 days ago

I have List of the infraction and All infraction is print in a foreach loop. I want to store some infraction id in the database using checkbox.

<table class="table table-bordered">
    @foreach($infractions as $infraction)
       <tr>
           <th>{{ $infraction->title }}</th>
           <td>
               <input type="checkbox" value="1" name="infraction{{ $infraction->id }}" data-toggle="toggle" data-on="Yes" data-off="No" data-onstyle="success" data-offstyle="danger">
               <input type="hidden" name="infraction_name{{ $infraction->id }}" value="{{ $infraction->id }}" />
           </td>
       </tr>
    @endforeach
</table>

I have no idea where I put submit button and how to get value from a checkbox into Controller to save data.

public function store(Request $request)
{
    for(int i=0;i<68;i++){
        $infraction_id=$_POST['infraction_name'.i];
        $infraction_true_false=$_POST['infraction'.i];
        $query="insert into inspection () value ()";
    }
    auth()->user()->inspections()->create($request->all());
}

14th July, 2018

irankhosravi left a reply on No Query Results For Model [App\User]. • 1 week ago

public function register(Request $request)
{
    if ($request->hasFile('image')) {
        $fileNameWithExt = $request->file('image')->getClientOriginalName();
        $filename = pathinfo($fileNameWithExt, PATHINFO_FILENAME);
        $extention = $request->file('image')->getClientOriginalExtension();
        $fileNameToStore = $filename.'_'.time().'.'.$extention;
        $path = $request->file('image')->storeAs('public/images', $fileNameToStore);
    } else {
        $fileNameToStore = 'noimage.jpg';
    }

    $user = new User();
    $user->first_name = $request->firstname;
    $user->last_name = $request->lastname;
    $user->email = $request->email;
    $user->password = md5($request->password);
    $user->mobile = $request->mobile;
    $user->national_code = $request->nasional_code;
    $user->birth_date = $request->birthdate;
    $user->document = $request->document;
    $user->educational = $request->educational;
    $user->gender = $request->gender;
    $user->side = $request->side;
    $user->image = $fileNameToStore;
    $user->save();
    return redirect('/');
}

irankhosravi left a reply on No Query Results For Model [App\User]. • 1 week ago

Ok, What to use instead of firstOrFail()?

irankhosravi left a reply on No Query Results For Model [App\User]. • 1 week ago

Do you mean LoginController.php file?

irankhosravi left a reply on No Query Results For Model [App\User]. • 1 week ago

Yes, But I enter the password incorrectly, I see this error...

irankhosravi left a reply on No Query Results For Model [App\User]. • 1 week ago

help

13th July, 2018

irankhosravi left a reply on No Query Results For Model [App\User]. • 1 week ago

Yes, you're right, just solve. that mistake that I said. Thankful

irankhosravi left a reply on No Query Results For Model [App\User]. • 1 week ago

Sorry if i speak bad

irankhosravi left a reply on No Query Results For Model [App\User]. • 1 week ago

WTF?

What do you mean?

irankhosravi left a reply on No Query Results For Model [App\User]. • 1 week ago

When I enter the password incorrectly, I see this error.

No query results for model [App\User].

And I'm logged in when I enter the password correctly.

irankhosravi left a reply on No Query Results For Model [App\User]. • 1 week ago

I know they are very insecure but my colleague working with android. According to her, the password should change to md5.

irankhosravi started a new conversation No Query Results For Model [App\User]. • 1 week ago

I changed password bcrypt to md5.

LoginController.php

use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

public function login(Request $request)
{
    $user = User::where('email', $request->email)
        ->where('password',md5($request->password))
        ->firstOrFail();
    Auth::login($user);
    return redirect('/');
}

When I login I see this error.

No query results for model [App\User].

12th July, 2018

irankhosravi left a reply on The File "C:\xampp\tmp\php8911.tmp" Does Not Exist • 1 week ago

So what's the solution?

irankhosravi left a reply on The File "C:\xampp\tmp\php8911.tmp" Does Not Exist • 1 week ago

So what's the solution?

9th July, 2018

irankhosravi left a reply on The File "C:\xampp\tmp\php8911.tmp" Does Not Exist • 1 week ago

So what's the solution?

irankhosravi left a reply on The File "C:\xampp\tmp\php8911.tmp" Does Not Exist • 1 week ago

I filled it like that, but display show like above.

protected function uploadImages($file)
{
    $year = Carbon::now()->year;
    $imagePath = "/upload/images/{$year}/";
    $filename = $file->getClientOriginalName();
    
    $file = $file->move(public_path($imagePath) , $filename);
    $file = $file->move(public_path($imagePath) , $filename);
    dd($file);
    
    $sizes = ["300" , "600" , "900"];
    $url['images'] = $this->resize($file->getRealPath() , $sizes , $imagePath , $filename);
    $url['thumb'] = $url['images'][$sizes[0]];

    return $url;
}

irankhosravi left a reply on The File "C:\xampp\tmp\php8911.tmp" Does Not Exist • 1 week ago

I writted

dd($file); // dumps the file, it exists.

I get this message

UploadedFile {#205 ▼ -test: false -originalName: "1.jpg" -mimeType: "image/jpeg" -size: 140203 -error: 0 #hashName: null path: "C:\xampp\tmp" filename: "phpA4F7.tmp" basename: "phpA4F7.tmp" pathname: "C:\xampp\tmp\phpA4F7.tmp" extension: "tmp" realPath: "C:\xampp\tmp\phpA4F7.tmp" aTime: 2018-07-09 16:31:54 mTime: 2018-07-09 16:31:54 cTime: 2018-07-09 16:31:54 inode: 0 size: 140203 perms: 0100666 owner: 0 group: 0 type: "file" writable: true readable: true executable: false file: true dir: false link: false linkTarget: "C:\xampp\tmp\phpA4F7.tmp" }

What's the solution? thanks.

irankhosravi left a reply on The File "C:\xampp\tmp\php8911.tmp" Does Not Exist • 1 week ago

So what's the solution?

irankhosravi left a reply on The File "C:\xampp\tmp\php8911.tmp" Does Not Exist • 1 week ago

I get this message:

array:6 [▼
  "_token" => "ElHg1YiLLFAUkFqVWUdUV2qwZ2DxX5c1L5XcocYw"
  "title" => "Apple"
  "description" => "Apple is a company."
  "body" => "Apple Inc. is an American multinational technology company headquartered in Cupertino, California, that designs, develops, and sells consumer electronics"
  "category" => array:2 [▼
    0 => "1"
    1 => "2"
  ]
  "images" => array:2 [▼
    "images" => array:4 [▼
      "original" => "/upload/images/2018/1.jpg"
      300 => "/upload/images/2018/300_1.jpg"
      600 => "/upload/images/2018/600_1.jpg"
      900 => "/upload/images/2018/900_1.jpg"
    ]
    "thumb" => "/upload/images/2018/300_1.jpg"
  ]
]

8th July, 2018

irankhosravi started a new conversation The File "C:\xampp\tmp\php8911.tmp" Does Not Exist • 1 week ago

I after install

composer require intervention/image

I want to upload image and after submit a form, I get this error.

The file "C:\xampp\tmp\php1D5F.tmp" does not exist

public function store(ArticleRequest $request)
{
    auth()->loginUsingId(1);
    $imagesUrl = $this->uploadImages($request->file('images'));

    $article = auth()->user()->article()->create(array_merge($request->all(), ['images' => $imagesUrl]));
    $article->categories()->attach(request('category'));


    return redirect(route('articles.index'));
}

I tried Change the code:

    $imagesUrl = $this->uploadImages($request->file('images'));
    return $imagesUrl;

It displaied return $imagesUrl well.

images  
300 "/upload/images/2018/300_tvto.jpg"
600 "/upload/images/2018/600_tvto.jpg"
900 "/upload/images/2018/900_tvto.jpg"
original    "/upload/images/2018/tvto.jpg"
thumb   "/upload/images/2018/300_tvto.jpg"

I think problem from array_merge

7th July, 2018

irankhosravi left a reply on How To See Expert Only In Own City In Laravel 5.4 • 2 weeks ago

Thank you for your criticism.

irankhosravi left a reply on How To See Expert Only In Own City In Laravel 5.4 • 2 weeks ago

I tried to fix it, but why admin does not see everyone.

    $city = City::first(); // you must be fix it yourself
    $expert = Role::find(2); // you must be change it

    if ($expert) {
        $schools = SchoolsList::where('city_id', $city->id)->latest()->paginate(25);
    } else {
        $schools = SchoolsList::latest()->paginate(25);
    }

    return view('Admin.inspection-failed.all', compact('schools'));

Solve the problem yourself using the code sample. thank you.

irankhosravi left a reply on How To See Expert Only In Own City In Laravel 5.4 • 2 weeks ago

It is very important for me

irankhosravi left a reply on How To See Expert Only In Own City In Laravel 5.4 • 2 weeks ago

None of these posts were completed.

irankhosravi left a reply on How To See Expert Only In Own City In Laravel 5.4 • 2 weeks ago

answer me.

irankhosravi left a reply on How To See Expert Only In Own City In Laravel 5.4 • 2 weeks ago

I see this error again

Call to a member function where() on array

Your error occurred on the following line.

return view('Admin.inspection-failed.all', compact('schools')->where(($city_id)));

irankhosravi started a new conversation How To See Expert Only In Own City In Laravel 5.4 • 2 weeks ago

My project have two role

  • admin
  • expert

admin must see all data of all city. expert must see all data of own city after registered.

public function index()
{
    $schools = SchoolsList::latest()->paginate(25);
    $city_id = SchoolsList::where('city_id')->first();
    $expert = Role::where('id', '=', 2);
    if ($expert){
        return view('Admin.inspection-failed.all', compact('schools')->where(($city_id)));
    }
    else{
        return view('Admin.inspection-failed.all', compact('schools'));
    }
}

Table of school

Schema::create('schools', function (Blueprint $table) {
    $table->increments('id');
    $table->integer('user_id')->unsigned();
    $table->foreign('user_id')->references('id')->on('users');
    $table->integer('city_id')->unsigned();
    $table->foreign('city_id')->references('id')->on('cities');
    $table->string('school_name');
    $table->string('status');
    $table->string('gender');
    $table->string('notes');
    $table->string('member_name');
    $table->string('type');
    $table->string('file_number');
    $table->string('phone');
    $table->string('address');
});

I want to when a expert login. Expert display data only own expert city.

6th July, 2018

irankhosravi started a new conversation How To Use Relationship Ajax With Laravel? • 2 weeks ago

In Laravel, for relationship with ajax in the file blade.php is as follow, for example:

{{ foreach($schhols as $school) }}
    <td>{{ $school->user->name }}</td>
    <td>{{ $school->user->address}}</td>
    <td>{{ $school->user->country}}</td>
{{ endforeach }}

But in ajax with laravel how do it?

    function load() {
        $.get('/read', function (data){
            $('#data').html("");
            $.each(data, function (key, val) {
                $('#data').append("<tr>"+
                    "<td>"+val.id+"</td>"+
                    "<td id='ename'>"+val.name+"</td>"+
                    "<td id='eaddress'>"+val.address+"</td>"+
                    "<td id='ecountry'>"+val.country+"</td>"+
                    "<td>"+
                        "<button class='btn btn-warning' id='edit' data-id="+val.id+">Edit</button>"+
                        "<button class='btn btn-danger' id='delete' data-id="+val.id+">Delete</button>"
                    +"</td>"+
                +"</tr>")
            });
        });
    }

Will this happen?

    "<td id='ename'>"+val.user.name+"</td>"+
    "<td id='eaddress'>"+val.user.address+"</td>"+
    "<td id='ecountry'>"+val.user.country+"</td>"+

4th July, 2018

irankhosravi left a reply on Ajax Post In Laravel 5.4 Return Error 500 • 2 weeks ago

aaaahhhhhhh, Why do you raise the sound? I made it.

irankhosravi left a reply on Ajax Post In Laravel 5.4 Return Error 500 • 2 weeks ago

Help

irankhosravi left a reply on Ajax Post In Laravel 5.4 Return Error 500 • 2 weeks ago

Answer my question.

irankhosravi left a reply on Ajax Post In Laravel 5.4 Return Error 500 • 2 weeks ago

What does it mean? How to do it?

irankhosravi started a new conversation Ajax Post In Laravel 5.4 Return Error 500 • 2 weeks ago

In my application Laravel 5 randomly send 500 Internal Server Error on ajax requests (for example, on ten 200 OK requests, one 500 Internal Server Error request). CSRF token is correctly set up:

This is my test ajax in laravel 5 (refer below)

$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});

$("form").submit(function (event) {
    event.preventDefault();
    site = $('#site').val();
    name = $('#name').val();
    $.post("{{ route('activity.store') }}", {site:site, name:name}, function (data) {
        $('#site').val('');
        $('#name').val('');
        console.log(data);
        load_activity();
    });
});

My blade.php

<meta name="csrf-token" content="{{ csrf_token() }}">

<form id="activity-forms" method="post">
    <div class="row">
        <div class="col-md-6">
            <div class="form-group">
                <label class="col-md-3" for="site">Site</label>
                <div class="col-md-9">
                    <select id="site" name="site" class="form-control col-md-12">
                        <option value="google">Google</option>
                        <option value="yahoo">Yahoo</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="form-group">
                <label class="col-md-3" for="name">Name</label>
                <div class="col-md-9">
                    <input type="text" id="name" name="name" class="form-control col-md-12">
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <button id="save-activity" type="submit" class="btn btn-success pull-left col-md-4 btn-lg">
            <span class="glyphicon glyphicon-ok" aria-hidden="true"></span> Save
        </button>
    </div>
</form>

And my route

$this->resource('activity', 'ActivityController');

But when i click on submit button I get this error.

Error

3rd July, 2018

irankhosravi left a reply on Ajax Post In Laravel 5.4 Return Error 500 • 2 weeks ago

How much are you paying

Delete it.

irankhosravi left a reply on Ajax Post In Laravel 5.4 Return Error 500 • 2 weeks ago

Answer my question.

irankhosravi left a reply on Ajax Post In Laravel 5.4 Return Error 500 • 2 weeks ago

public function read_activity()
{
    $activities = Activity::all();
    return response()->json($activities);
}

$this->get('/read-activity', '[email protected]_activity');

irankhosravi left a reply on Ajax Post In Laravel 5.4 Return Error 500 • 2 weeks ago

I tryed it But I get MethodNotAllowedHttpException error.

irankhosravi left a reply on Ajax Post In Laravel 5.4 Return Error 500 • 2 weeks ago

ActivityController

public function store(Request $request)
{
    if($request->ajax()) {
        $request->validate([
            'site' => 'required',
            'name' => 'required',
        ]);

        $activity = new Activity();
        $activity->site = $request->site;
        $activity->name = $request->name;
        $activity->save();

        return response()->json(['data' => $request->all(), 'id' => $activity->id]);
    }
}

load_activity

        function load_activity() {
            $.get('read-activity', function (data){
                $('#data').html("");
                $.each(data, function (key, val) {
                    $('#data').append("<tr>"+
                        "<td>"+val.id+"</td>"+
                        "<td id='esite'>"+val.site+"</td>"+
                        "<td id='ename'>"+val.name+"</td>"+
                        "<td>"+
                        "<div class='btn-group-xs'>"+
                        "<button class='btn btn-warning' id='edit_activity' data-id="+val.id+">Edit</button>"+
                        "<button class='btn btn-danger' id='delete_activity' data-id="+val.id+">Delete</button>"+
                        "</div>"+
                        "</td>"+
                        +"</tr>"
                    )
                });
            });
        }

irankhosravi left a reply on Ajax Post In Laravel 5.4 Return Error 500 • 2 weeks ago

No I get this error. I am editing it.

irankhosravi started a new conversation Ajax Post In Laravel 5.4 Return Error 500 • 2 weeks ago

In my application Laravel 5 randomly send 500 Internal Server Error on ajax requests (for example, on ten 200 OK requests, one 500 Internal Server Error request). CSRF token is correctly set up:

This is my test ajax in laravel 5 (refer below)

$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});

$("form").submit(function (event) {
    event.preventDefault();
    site = $('#site').val();
    name = $('#name').val();
    $.post("{{ route('activity.store') }}", {cluster:cluster, group:group}, function (data) {
        $('#site').val('');
        $('#name').val('');
        console.log(data);
        load_activity();
    });
});

My blade.php

<meta name="csrf-token" content="{{ csrf_token() }}">

<form id="activity-forms" method="post">
    <div class="row">
        <div class="col-md-6">
            <div class="form-group">
                <label class="col-md-3" for="site">Site</label>
                <div class="col-md-9">
                    <select id="site" name="site" class="form-control col-md-12">
                        <option value="google">Google</option>
                        <option value="yahoo">Yahoo</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="form-group">
                <label class="col-md-3" for="name">Name</label>
                <div class="col-md-9">
                    <input type="text" id="name" name="name" class="form-control col-md-12">
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <button id="save-activity" type="submit" class="btn btn-success pull-left col-md-4 btn-lg">
            <span class="glyphicon glyphicon-ok" aria-hidden="true"></span> Save
        </button>
    </div>
</form>

And my route

$this->resource('activity', 'ActivityController');

But when i click on submit button I get this error.

Error

1st July, 2018

irankhosravi left a reply on How To Save A School_id By Applicaion_submit Id In Laravel? • 2 weeks ago

<form action="{{ route('submit-application.store')}}" method="post">
    {{ csrf_field() }}
    <div class="radio">
        <label for="school">School</label>
        <input type="radio" value="Scool" id="school" name="application">
        <br>
        <label for="equipment">Equipment</label>
        <input type="radio" value="Equipment" id="equipment" name="application">
        <br>
        <label for="level">Level</label>
        <input type="radio" value="Level" id="level" name="application">
        <br>
        <button type="submit" class="btn-warning btn">ارسال درخواست</button>
    </div>
</form>

But I think we should define a <input type="hidden">tag here

<input type="hidden" name="school_id" value="{{ $school_id }}">

irankhosravi started a new conversation How To Save A School_id By Applicaion_submit Id In Laravel? • 2 weeks ago

How to save a school_id by applicaion_submit id in laravel?

SubmitApplicationConteoller.php

public function store(Request $request)
{

// return $request->all(); $form = new SubmitApplication(); $form->school_id = School::id; $form->requisition_id = Requisition::id; $form->approved = 0; $form->application = $request->application; $form->save(); return redirect(route('submit-application.create'))->with('success', 'اطلاعات با موفقیت ذخیره شد.'); }

For submit_applications table

    Schema::create('submit_applications', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('requisition_id')->nullable()->unsigned();
        $table->integer('school_id')->nullable()->unsigned();
        $table->integer('approved')->nullable(true);
        $table->string('application')->nullable(true);
        $table->timestamps();
        $table->foreign('requisition_id')->references('id')->on('requisitions');
        $table->foreign('school_id')->references('id')->on('schools');
    });

26th June, 2018

irankhosravi left a reply on Trying To Get Property Of Non-object • 3 weeks ago

@Cronix

Excuse me I made it myself.

public function show($id)
{
    $school = School::with('user')->where('id', $id)->first();
    //..
}

irankhosravi left a reply on Trying To Get Property Of Non-object • 3 weeks ago

Help

irankhosravi left a reply on Trying To Get Property Of Non-object • 3 weeks ago

You are crazy.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.