irankhosravi

irankhosravi

Member Since 1 Year Ago

Experience Points
17,470
Total
Experience

2,530 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
1
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    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 Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

Level 4
17,470 XP
Nov
13
1 week ago
Activity icon

Started a new Conversation Laravel Ajax Validations

marketing.blade.php

<form method="POST" id="form-marketing" action="{{ route('register') }}" enctype="multipart/form-data">
    @csrf
    <div class="form-group row">
        <label for="first_name" class="col-md-2 col-form-label text-md-right">{{ __('First name') }}</label>

        <div class="col-md-10">
            <input id="first_name" type="text" class="form-control @error('first_name') is-invalid @enderror" name="first_name" value="{{ old('first_name') }}" autocomplete="first_name" autofocus>

            @error('first_name')
            <span class="invalid-feedback" role="alert">
            <strong>{{ $message }}</strong>
        </span>
            @enderror
        </div>
    </div>
    <div class="row">
        <div class="wizard-buttons">
            <button type="submit" id="submitAdd" class="btn btn-next">
                Save & Continue
            </button>
        </div>
    </div>
</form>

ajax

<script>
    $("#form-marketing").on('submit',(function(e) {
        e.preventDefault();
        var formData = new FormData(this);
        $.ajax({
            url: $(this).attr('action'), // url where to submit the request
            type : "POST", // type of action POST || GET
            data:formData,
            contentType: false,
            processData: false,
            cache: false,
            dataType : 'json', // data type
            success : function(data) {
                console.log(data.res);
            },
            error: function(data) {
                console.log(data.msg);
            }
        });
    }));
    $("#submitAdd").on("click", function(e) {
        e.preventDefault();

        $("#form-marketing").submit();
    });
</script>

web.php

if ($options['marketing'] ?? true) {
    Route::get('marketing', '[email protected]')->name('marketing');
    Route::post('marketing/store', '[email protected]')->name('marketing.store');
}

RegisterController.php

public function register(UserRequest $request)
{
    $user = new User;
.......
}

UserRequest .php

public function rules()
{
    return [
        'first_name' => ['required', 'string', 'max:255'],

I want to if the first_name field is blank, show warning and stop.

Oct
30
3 weeks ago
Activity icon

Started a new Conversation Property [name] Does Not Exist On This Collection Instance

I have a table holds committee_category information.

categories

I am trying to pass data to view using the following code in the controller file:

public function index()
{
    $committee_categories = Committee::latest()->get();
    return view('Home.index', compact( 'committee_categories'));
}

When I try to show the code as shown below,

@foreach($committee_categories->split($committee_categories->count()/1) as $row)
    <div class="col-md-4">
        @foreach($row as $committee)
            <a class="dropdown-item text-right" href="#">{{ $committee->categories->name }}</a>
        @endforeach
    </div>
@endforeach

I get error that says:

Property [name] does not exist on this collection instance.

Committee.php

public function categories()
{
    return $this->belongsToMany(Category::class);
}
Oct
25
4 weeks ago
Activity icon

Started a new Conversation How To Create Recaptch In Laravel

I create a recaptha but I see this error. What is this error?

Client error: POST https://www.google.com/recaptcha/api/siteverify resulted in a 400 Bad Request response: { "success": false, "error-codes": [ "bad-request" ] }

Oct
20
1 month ago
Activity icon

Replied to How To Create Master In Php?

@joveice

I did not use laravel and blade.

I want to use only php mvc.

Oct
19
1 month ago
Activity icon

Replied to How To Create Master In Php?

I don't want to use blades for now.

Activity icon

Replied to How To Create Master In Php?

@nakov

Yes , I want to create simple master in php

Activity icon

Started a new Conversation How To Create Master In Php?

I want to create a simple master in theme.

master.php

<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<title>Hello, world!</title>
</head>
<body>
<?php require_once ('layouts/header.php') ?>
<?php require_once ($content) ?>
<?php require_once ('layouts/footer.php') ?>
</body>
</html>

index.php

 <?php $content = 'index.php' ?>
 <?php require_once ('master.php'); ?>

<div class="container">
  <div class="row">
    <div class="col-sm">
      One of three columns
    </div>
    <div class="col-sm">
      One of three columns
    </div>
    <div class="col-sm">
      One of three columns
    </div>
  </div>
</div>
Oct
18
1 month ago
Activity icon

Replied to Creating Default Object From Empty Value

The session number phone is not empty

Activity icon

Replied to Creating Default Object From Empty Value

The session number phone is not empty.

mobile number

Activity icon

Replied to Creating Default Object From Empty Value

@nakov

I already registered and now I just want to change my mobile number

I get this error?

SQLSTATE[HY000]: General error: 1364 Field 'first_name' doesn't have a default value (SQL: insert into users (mobile, code, updated_at, created_at) values (09389267856, 5256, 2019-10-18 11:06:10, 2019-10-18 11:06:10))

Activity icon

Replied to Creating Default Object From Empty Value

I change this line: dd($user); show null.

Activity icon

Replied to Creating Default Object From Empty Value

I added this

dd($newPhone);

I see this

"0123456789"
Activity icon

Started a new Conversation Creating Default Object From Empty Value

How to change mobile number?

public function updatePhoneNumber(MobileRequest $request)
{
    $oldPhone = Session::get('mobile');
    $newPhone = $request->mobile;
    $exists = User::whereMobile($newPhone)->first();
    if($exists) {
        alert()->message('This number is already registered', 'warning')->persistent('ok');
    }
    $user = User::whereMobile($oldPhone)->first();
    $user->mobile = $newPhone;
    $code = rand(1000, 9999);
    $user->code = $code;

    if($user->save()){
        $smsHelper = new SMSHelper();
        $smsHelper->sendSms(['code' => $code,'receiver' => $request->mobile]);
        Session::put('mobile',$newPhone);
        return back();
    }
}

I get this error.

Creating default object from empty value

This error in the following error occurred

 $user->mobile = $newPhone;

I don't understand what the problem is with this line.

Oct
17
1 month ago
Activity icon

Replied to Object Of Class Illuminate\Database\Eloquent\Builder Could Not Be Converted To Int

I get this error.

Creating default object from empty value

This error in the following error occurred

$user->user_id = auth()->user()->id;
Activity icon

Replied to Object Of Class Illuminate\Database\Eloquent\Builder Could Not Be Converted To Int

I get this error.

Object of class App\Coupon could not be converted to int

This error in the following error occurred

$des -=1;
Activity icon

Replied to Object Of Class Illuminate\Database\Eloquent\Builder Could Not Be Converted To Int

@sinnbeck I want to create a 30% discount code.

@munazzil I change it to toArray() but I did not solve my problem.

@nakov I did not catch

Activity icon

Started a new Conversation Object Of Class Illuminate\Database\Eloquent\Builder Could Not Be Converted To Int

I am trying to pass data to a datatable in laravel 5 but have the following error.

Object of class Illuminate\Database\Eloquent\Collection could not be converted to int

The error line is one which corresponds to where I am selecting desired information from my model.

  $price = (Coupon::where('percent') / 100) * $order->categories->price->get();
Oct
11
1 month ago
Activity icon

Replied to Undefined Property: Illuminate\Auth\AuthManager::$id

@joveice this line

    $marketings = User::where('id', auth()->id)->get();
Activity icon

Started a new Conversation Undefined Property: Illuminate\Auth\AuthManager::$id

I want to show users, when a login own marketing.

public function index ()
{
    if (auth()->user()->level == 'admin') 
    {
        $marketings = User::latest()->paginate(25);
    }
    else if (auth()->user()->level == 'marketing')
    {

        $marketings = User::where('id', auth()->id)->get();

    }
    return view('Admin.marketing.index', compact('marketings'));
}

but I see this error,

Undefined property: Illuminate\Auth\AuthManager::$id

Oct
08
1 month ago
Activity icon

Replied to How To Add A Word In Javascript

When I added price only

$('#price').html($selected.data('price'));

Is on display. but I when add word of Price and $. Is did not display.

Activity icon

Replied to How To Add A Word In Javascript

How to show? Price and $

Activity icon

Replied to How To Add A Word In Javascript

Nothing, white page

Activity icon

Replied to How To Add A Word In Javascript

No i did not get an error in console

Activity icon

Started a new Conversation How To Add A Word In Javascript

I want to add a word of price, but it did not show.

For example: Price: 49 $

$('#price').html($selected.data('Price'+'price'+' $'));
Oct
05
1 month ago
Activity icon

Replied to Property [id] Does Not Exist On This Collection Instance.

I found. In AppServiceProvider.php on boot method.

view()->composer('*', function($view) {
    $view->with('block', Block::all());
});
Activity icon

Replied to Property [id] Does Not Exist On This Collection Instance.

What do you have in this view then?

NONE.

Activity icon

Replied to Property [id] Does Not Exist On This Collection Instance.

I added dd($block) in method edit of controller.

dd

Activity icon

Replied to Property [id] Does Not Exist On This Collection Instance.

I tried it but I get this error again

Property [id] does not exist on this collection instance.

Activity icon

Replied to Property [id] Does Not Exist On This Collection Instance.

edit.blade.php

<div class="container">
    <form class="form-horizontal" action="{{ route('blocks.update', $block[0]->id) }}" method="post">
        @csrf
        @method('PATCH')
        @include('Admin.layouts.errors')
        <div class="form-group">
            <label for="body">Body</label>
            <textarea class="form-control" rows="10" id="body" name="body">{{ $block[0]->body ? : old('body') }}</textarea>
        </div>
        <div class="form-group">
            <button type="submit" class="btn btn-primary">Save</button>
        </div>
    </form>
</div>
Activity icon

Replied to Property [id] Does Not Exist On This Collection Instance.

Which view?

I shared the code from that view

@foreach($blocks as $block)....
Activity icon

Started a new Conversation Property [id] Does Not Exist On This Collection Instance.

When I click edit button . I get this error

Property [id] does not exist on this collection instance.

web.php

Route::resource('blocks', 'BlockController');

BlockController.php

public function index()
{
    $blocks = Block::all();
    return view('Admin.blocks.index', compact('blocks'));
}

public function edit(Block $block)
{
    return view('Admin.blocks.edit', compact('block'));
}

index.blade.php

@foreach($blocks as $block)
    <tr>
        <td>{!! str_limit($block->body, 30)  !!}</td>
        <td>
            <a href="{{ route('blocks.edit',  $block->id) }}"  class="btn btn-primary">Edit</a>
        </td>
    </tr>
@endforeach
Oct
03
1 month ago
Activity icon

Replied to How To Create Pagination With Ajax?

How tot create paagination with ajax in laravel?

Sep
28
1 month ago
Activity icon

Started a new Conversation How To Create Pagination With Ajax?

I have this view called categories/index.blade.php which gets included in index.blade.php:

@foreach($categories as $category)
    <tr>
        <td>{{ $category->name }}</td>
        <td>{{ $category->getParent->name }}</td>
        <td>
            <form action="{{ route('categories.destroy', ['id' => $category->id]) }}" method="post">
                @method('delete')
                @csrf()
                <div class="btn-group btn-group-sm">
                    <a href="{{ route('categories.edit' , ['id' => $category->id]) }}"  class="btn btn-primary">edit</a>
                    <button type="submit" class="btn btn-danger">delete</button>
                </div>
            </form>
        </td>
    </tr>
@endforeach
.
.   
.

{!! $categories->links() !!}

CategoryController.php

public function index(Request $request)
{
    if ($request->ajax()) {
        $categories = Category::latest()->paginate(5);
        return view('Admin.categories.index', compact('categories'));
    }
}

web.php

Route::resource('categories', 'CategoryController');

ajax

<script>
    $(document).ready(function () {
        $(document).onclick('.pagination a', function (event) {
            event.preventDefault();
            var page = $(this).attr('href').split('page=')[1];
            fetch_data(page);
        });
        function fetch_data(page) {
            $.ajax({
                url: 'fa/admin/categories?page='+page,
                success: function (data) {
                    $('.table-responsive').html(data);
                }
            })
        }
    });
</script>
Sep
25
1 month ago
Activity icon

Replied to How To Add Two Language?nn

Answer my question.....

Activity icon

Replied to How To Add Two Language?nn

What is the solution?

Activity icon

Replied to How To Add Two Language?nn

@snapey

Execuse me I deleted my post.

Activity icon

Replied to How To Add Two Language?nn

My problem did not solve, too It go to http://localhost:8000/admin/dashboard address again

Activity icon

Replied to How To Add Two Language?nn

I replaced in following line:

    return $next($request).app()->getLocale();

but i get this error.

Trying to get property of non-object

Sep
24
1 month ago
Activity icon

Started a new Conversation How To Add Two Language?nn

My site is two languages. And I want to when after login an admin, go to https://example.com/en/admin/dashboard.

My Middleware

public function handle($request, Closure $next)
{
    if (auth()->check())
    {
        if (auth()->user()->isAdmin())
        {
            return $next($request).app()->getLocale();
        }
    }
    return redirect('/login');
}

i get this error

Trying to get property of non-object

Sep
23
1 month ago
Activity icon

Started a new Conversation Too Few Arguments To Function

I am getting the following error while trying to insert into the table categories.

CategoryController.php

public function store(CategoryRequest $request)
{
    $category = auth()->user()->categories($request->all());
    $category->save();
    return redirect(route('categories.index'));
}

User.php

public function categories()
{
    return $this->hasMany(Category::class);
}

but I get this error.

Too few arguments to function Illuminate\Database\Eloquent\Relations\HasOneOrMany::save(), 0 passed in C:\xampp\htdocs\urmiahardware\blog\app\Http\Controllers\Admin\CategoryController.php on line 43 and exactly 1 expected

Activity icon

Replied to Why Do Not Display Dd After Register

RegisterController.php

public function register(UserRequest $request )
{
dd('hello world');
    $this->validator($request->all())->validate();
}

Yes I will probably get validation errors and will be redirected back to the form. But dd('') doesn't show that.

Activity icon

Replied to Why Do Not Display Dd After Register

I change this line:

if ($options['register'] ?? true) {
    Route::get('register', 'Auth\[email protected]')->name('register');
    Route::post('register', 'Auth\[email protected]');
}

But it did not solve my problem.

Activity icon

Replied to Why Do Not Display Dd After Register

register.blade.php

<form action="{{ route('register') }}" method="post">

Answer my question/.

Activity icon

Started a new Conversation Why Do Not Display Dd After Register

I've tested it several times but it doesn't show . I getted the output with dd('hello');

web.php

if ($options['register'] ?? true) {
    Route::get('register', 'Auth\[email protected]')->name('register');
    Route::post('register', 'Auth\[email protected]')->name('register');
}

RegisterController.php

public function register(UserRequest $request )
{
dd('hello world');
    $this->validator($request->all())->validate();
}
Sep
22
2 months ago
Activity icon

Replied to Method App\Http\Requests\ProductRequest::categories Does Not Exist.

I get this error again.

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'urmiahardware_blog.category_product' doesn't exist (SQL: insert into category_product (category_id, product_id) values (3, 1))

Activity icon

Started a new Conversation Method App\Http\Requests\ProductRequest::categories Does Not Exist.

Method App\Http\Requests\ProductRequest::categories does not exist.

Method App\Http\Requests\ProductRequest::categories does not exist.

This is my codes..

public function store(ProductRequest $request)
{
    $product = new Product();
    $product->user_id = auth()->user()->id;
    $product->title = $request->title;
    $product->lang = $request->lang;
    $product->body = $request->body;
    $product->price = $request->price;
    if($request->has('image')) {
        $image = $request->file('image');
        $filename = $image->getClientOriginalName();
        $image->move(public_path('images/products'), $filename);
        $product->image = $request->file('image')->getClientOriginalName();
    }
    $request->categories()->attach($request->category);
    $product->save();
    return redirect()->route('products.index');
}

Product.php

public function categories()
{
    return $this->hasMany(Category::class);
}