oxbir

Member Since 1 Year Ago

Experience Points
14,630
Total
Experience

370 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
3
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

  • Community Pillar

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

Level 3
14,630 XP
Dec
06
1 month ago
Activity icon

Started a new Conversation How Can The First Cities Of The Province Be Displayed To The User After Selecting The Country List Option?

We have 3 select option, Country, State, City.

city

After selecting the country, I want to take the ID of city number 1 from the database and display it.

I want to when select America, List of cities New York bring me.

<div class="col-md-2">
    <div class="form-group">
        <label for="country_id">Country</label>
        <select id="country_id" name="country_id" class="form-control">
            <option></option>
            @foreach($countries as $country)
                <option {{ optional(auth()->user()->country)->id == $country->id ? 'selected' : '' }} value="{{ $country->id }}">
                    {{ $country->name }}
                </option>
            @endforeach
        </select>
    </div>
</div>
<div class="col-md-2">
    <div class="form-group">
        <label for="state_id">State</label>
        <select id="state_id" name="state_id" class="form-control">

        </select>
        <input type="text" name="state_name" value="{{ auth()->user()->state_name }}" id="state_id" class="form-control d-none">
    </div>
</div>
<div class="col-md-2">
    <div class="form-group">
        <label for="city_id">City</label>
        <select id="city_id" name="city_id" class="form-control">

        </select>
        <input type="text" name="city_name" value="{{ auth()->user()->city_name }}" id="city_id" class="form-control d-none">
    </div>
</div>

js

$(document).on('change', '#country_id', function() {
    let country_id = $(this).val();
	if(country_id == 1){
		$('#city_id').find('#state_id');
	}
    let select = $('#state_id');
    $.ajax({
        type: 'get',
        url: '{{ route('findIDCoubtry') }}',
        data: {'id':country_id},
        success: function(data){
            select.html('');
            for (var i = 0; i < data.length; i++){
                select.append('<option value="'+data[i].id+'">'+data[i].name+'</option>');
            }
        },
        error: function(){
            console.log('this is a error');
        },
    });
}).trigger('change');

Controller

public function findIDCountry(Request $request)
{
    $data = State::select('name', 'id')->where('country_id', $request->id)->take(100)->get();
    return $data;
}

public function findIDState(Request $request)
{
    $data = City::select('name', 'id')->where('state_id', $request->id)->take(100)->get();
    return $data;
}
Nov
30
1 month ago
Activity icon

Started a new Conversation How To Change This Code To Laravel?

This code

for($i = 0; $i < count($request->skill_name); $i++){
    $skill = Skill::where('skill_name', '=', $request->skill_name[$i])->first();
    if(!$skill) {
        $skill = Skill::create([
            'skill_name' => $request->skill_name[$i],
        ]);
    }
    $user->skills()->attach($skill->id, ['level' => $request->level[$i]]);
}
Nov
29
1 month ago
Activity icon

Replied to SQLSTATE[22007] Invalid Datetime Format 1366 Incorrect Integer Value:a Field For Column

I changed this code

//dd($request->skill_name);
$user->skills()->detach();
if ($request->skill_name) {
    foreach ($request->skill_name as $key => $skill_name) {
        $user->skills()->sync($skill_name, [
            'user_id' => auth()->id(),
            'level' => $request->level[0],
            'skill_name' => $request->skill_name[0],
        ]);
    }
}

I get this error.

SQLSTATE[HY000]: General error: 1364 Field 'skill_name' doesn't have a default value (SQL: insert into skill_user (skill_id, user_id) values (Laravel, 1))

Activity icon

Replied to SQLSTATE[22007] Invalid Datetime Format 1366 Incorrect Integer Value:a Field For Column

@sr57

But what is this code?

This code is for attaching of the database.

Activity icon

Replied to SQLSTATE[22007] Invalid Datetime Format 1366 Incorrect Integer Value:a Field For Column

If you have a solution, put a sample full code here.

In fact, my code is all wrong. If you were me, How did you save the skills?

Activity icon

Replied to SQLSTATE[22007] Invalid Datetime Format 1366 Incorrect Integer Value:a Field For Column

This

public function up()
{
    Schema::create('skills', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->bigInteger('user_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        $table->string('skill_name');
        $table->smallInteger('level');
        $table->timestamps();
    });

    Schema::create('skill_user', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->bigInteger('skill_id')->unsigned()->nullable();
        $table->foreign('skill_id')->references('id')->on('skills')->onDelete('cascade');
        $table->bigInteger('user_id')->unsigned()->nullable();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        $table->unique(['skill_id' , 'user_id']);
        $table->string('skill_name');
        $table->smallInteger('level');
    });
}
Activity icon

Replied to SQLSTATE[22007] Invalid Datetime Format 1366 Incorrect Integer Value:a Field For Column

@sr57

I did not understand what you meant.

What should I change?

Can you give an example?

Activity icon

Started a new Conversation SQLSTATE[22007] Invalid Datetime Format 1366 Incorrect Integer Value:a Field For Column

After login a user, The user enters this skills form, selects the skills.

skills

*A user can enter multiple skills, and save in database. The field of name

  • skill_name

  • level And in table

  • skill_name

  • level

  • user_id I don't know if the skills and skill_user table should be, or not, I don't know. What would you do if you were me? Can you show me the cleanest coding?*

      public function up()
     {
      Schema::create('skills', function (Blueprint $table) {
          $table->bigIncrements('id');
          $table->bigInteger('user_id')->unsigned();
          $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
          $table->string('skill_name');
          $table->smallInteger('level');
          $table->timestamps();
      });
    
      Schema::create('skill_user', function (Blueprint $table) {
          $table->bigInteger('skill_id')->unsigned()->nullable();
          $table->foreign('skill_id')->references('id')->on('skills')->onDelete('cascade');
          $table->bigInteger('user_id')->unsigned()->nullable();
          $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
          $table->unique(['skill_id' , 'user_id']);
         });
        }
    

blade

showDynamicExperimental();
function showDynamicExperimental()
{
    let html = '' +
        '@foreach(auth()->user()->skills as $skill)\n'+
        '<div class="col-md-6 position-relative">\n' +
        '<i class="fas fa-times text-danger position-absolute"></i>' +
        '<div class="row">\n' +
        '<div class="col-md-8">\n' +
        '<div class="form-group">\n' +
        '<label for="skill_name">skill_name</label>\n' +
        '<input type="text" id="skill_name" name="skill_name[]" class="form-control" value="{{ $skill->skill_name }}">\n' +
        '</div>\n' +
        '</div>\n' +
        '<div class="col-md-4">\n' +
        '<div class="form-group">\n' +
        '<label for="level">level</label>\n' +
        '<select class="form-control" id="level" name="level[]">\n' +
        '<option value="1" {{ $skill->level == 1 ? 'selected' : '' }}>★☆☆☆☆</option>\n'+
        '<option value="2" {{ $skill->level == 2 ? 'selected' : '' }}>★★☆☆☆</option>\n'+
        '<option value="3" {{ $skill->level == 3 ? 'selected' : '' }}>★★★☆☆</option>\n'+
        '<option value="4" {{ $skill->level == 4 ? 'selected' : '' }}>★★★★☆</option>\n'+
        '<option value="5" {{ $skill->level == 5 ? 'selected' : '' }}>★★★★★</option>\n'+
        '</select>\n'+
        '</div>\n' +
        '</div>\n' +
        '</div>\n' +
        '</div>\n ' +
        '@endforeach';
    $('#showExperimental').append(html);
}

Controller

$user->skills()->detach();

if ($request->skill_name) {
    foreach ($request->skill_name as $key => $value) {
        $user->skills()->attach($value, [
            'user_id' => auth()->id(),
            'level' => $request->level[$key],
        ]);
    }
}

User.php

public function skills()   
{
    return $this->belongsToMany(Skill::class)->withPivot('skill_name');
}

I get this error.

error

Nov
27
1 month ago
Activity icon

Replied to Trying To Access Array Offset On Value Of Type Null

You go get lost. I wasn't with you.

Activity icon

Replied to Trying To Access Array Offset On Value Of Type Null

Can you show me the cleanest coding?

Activity icon

Replied to Trying To Access Array Offset On Value Of Type Null

@automica

After login a user, The user enters this skills form, selects the skills.

skills

A user can enter multiple skills, and save in database.

The field of name

  • skill_name
  • level

And in table

  • skill_name
  • level
  • user_id

I don't know if the skills and skill_user table should be, or not, I don't know.

What would you do if you were me?

Can you show me the cleanest coding?

Activity icon

Replied to Trying To Access Array Offset On Value Of Type Null

@automica

When after save , I see in table of skill_user table,

[![table][1]][1]
Activity icon

Replied to Trying To Access Array Offset On Value Of Type Null

@automica

Nowhere my blade, there is no skill_name. only there is skill_id

Activity icon

Replied to Trying To Access Array Offset On Value Of Type Null

I get this message

array:2 [▼
  0 => "laravel"
  1 => "php"
]

array:2 [▼
  0 => "3"
  1 => "5"
 ]
Activity icon

Replied to Trying To Access Array Offset On Value Of Type Null

@automica

I get this error again

error

skill_user table

table

Activity icon

Replied to Trying To Access Array Offset On Value Of Type Null

What is the solution?

And

What am I doing?

Activity icon

Replied to Trying To Access Array Offset On Value Of Type Null

@automica

I see this error.

error

showDynamicExperimental();
function showDynamicExperimental()
{
    let html = '' +
        '@foreach(auth()->user()->skills as $skill)\n'+
Activity icon

Replied to Trying To Access Array Offset On Value Of Type Null

My form is like this.

skills

What do you suggest ??

I changed this code

Controller

$user->skills()->detach();
if ($request->skill_id) {
    foreach($request->skill_id as $key => $social){
        $user->socials()->attach($social, ['skill_id' => $request->link[$key]]);
    }
}

blade

showDynamicExperimental();
function showDynamicExperimental()
{
	let html = '' +
		'@foreach(auth()->user()->skills as $skill)\n'+
		'<div class="col-md-6 position-relative">\n' +
		'<i class="fas fa-times text-danger position-absolute"></i>' +
		'<div class="row">\n' +
		'<div class="col-md-8">\n' +
		'<div class="form-group">\n' +
		'<label for="skill_id">skill_name</label>\n' +
		'<input type="text" id="skill_id" name="skill_id[]" class="form-control" value="{{ $skill->skill_name }}">\n' +
		'</div>\n' +
		'</div>\n' +
		'<div class="col-md-4">\n' +
		'<div class="form-group">\n' +
		'<label for="level">level</label>\n' +
		'<select class="form-control" id="level" name="level[]">\n' +
		'<option value="1" {{ $skill->level == 1 ? 'selected' : '' }}>★☆☆☆☆</option>\n'+
		'<option value="2" {{ $skill->level == 2 ? 'selected' : '' }}>★★☆☆☆</option>\n'+
		'<option value="3" {{ $skill->level == 3 ? 'selected' : '' }}>★★★☆☆</option>\n'+
		'<option value="4" {{ $skill->level == 4 ? 'selected' : '' }}>★★★★☆</option>\n'+
		'<option value="5" {{ $skill->level == 5 ? 'selected' : '' }}>★★★★★</option>\n'+
		'</select>\n'+
		'</div>\n' +
		'</div>\n' +
		'</div>\n' +
		'</div>\n ' +
		'@endforeach';
	$('#showExperimental').append(html);
}
Activity icon

Started a new Conversation Trying To Access Array Offset On Value Of Type Null

table

public function up()
{
    Schema::create('skills', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->bigInteger('user_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        $table->string('skill_name');
        $table->smallInteger('level');
        $table->timestamps();
    });

    Schema::create('skill_user', function (Blueprint $table) {
        $table->bigInteger('skill_id')->unsigned()->nullable();
        $table->foreign('skill_id')->references('id')->on('skills')->onDelete('cascade');
        $table->bigInteger('user_id')->unsigned()->nullable();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        $table->unique(['skill_id' , 'user_id']);
    });
}

blade

    showDynamicExperimental();
function showDynamicExperimental()
{
    let html = '' +
        '@foreach(auth()->user()->skills as $skill)\n'+
        '<div class="col-md-6 position-relative">\n' +
        '<i class="fas fa-times text-danger position-absolute"></i>' +
        '<div class="row">\n' +
        '<div class="col-md-8">\n' +
        '<div class="form-group">\n' +
        '<label for="skill_name">skill_name</label>\n' +
        '<input type="text" id="skill_name" name="skill_name[]" class="form-control" value="{{ $skill->skill_name }}">\n' +
        '</div>\n' +
        '</div>\n' +
        '<div class="col-md-4">\n' +
        '<div class="form-group">\n' +
        '<label for="level">level</label>\n' +
        '<select class="form-control" id="level" name="level[]">\n' +
        '<option value="1" {{ $skill->level == 1 ? 'selected' : '' }}>★☆☆☆☆</option>\n'+
        '<option value="2" {{ $skill->level == 2 ? 'selected' : '' }}>★★☆☆☆</option>\n'+
        '<option value="3" {{ $skill->level == 3 ? 'selected' : '' }}>★★★☆☆</option>\n'+
        '<option value="4" {{ $skill->level == 4 ? 'selected' : '' }}>★★★★☆</option>\n'+
        '<option value="5" {{ $skill->level == 5 ? 'selected' : '' }}>★★★★★</option>\n'+
        '</select>\n'+
        '</div>\n' +
        '</div>\n' +
        '</div>\n' +
        '</div>\n ' +
        '@endforeach';
    $('#showExperimental').append(html);
}

Controller

    $user->skills()->detach();
    if ($request->skill_name) {
        foreach($request->skill_name as $key => $social){
            $user->socials()->attach($social, ['skill_name' => $request->link[$key]]);
        }
    }

User.php

public function skills()
{
    return $this->belongsToMany(Skill::class);
}

I get this error

Trying to access array offset on value of type null

Activity icon

Replied to How To Add Font Awesome To Select Option In Mobile?

@piljac1

How?

Can you send a sample from code?

Nov
25
1 month ago
Activity icon

Started a new Conversation How To Add Font Awesome To Select Option In Mobile?

I want to add symbols to my selected list. I put the text in the header. When I tried to use the icon in the selected menu, it did not work on mobile. But it works perfectly outside the selection menu. Is it possible to place the icon in the menu select option or is it simply impossible to do? How can I do this?

In Computer

star

In mobile

mobile

html

<link rel="stylesheet" href="themes/fontawesome/css/all.min.css">

<select class="form-control" id="reading_skill" name="reading_skill[]">
	<option value="1">&#xf006; &#xf006; &#xf006; &#xf006; &#xf005;</option>
	<option value="2">&#xf006; &#xf006; &#xf006; &#xf005; &#xf005;</option>
	<option value="3">&#xf006; &#xf006; &#xf005; &#xf005; &#xf005;</option>
	<option value="4">&#xf006; &#xf005; &#xf005; &#xf005; &#xf005;</option>
	<option value="5">&#xf005; &#xf005; &#xf005; &#xf005; &#xf005;</option>
</select>

css

select#listening_skill, select#writing_skill, select#reading_skill, select#level {
    font-family: 'FontAwesome';
    /*content: '&#xf006;';*/
    font-weight: 900;
}
Activity icon

Replied to How To Insert Validate With Javascript?

Can anyone answer my question?

I want something like that. https://codesandbox.io/s/affectionate-leftpad-cz45j?file=/src/App.js

But this is what I want to convey to the source. instead of alert('it is an error');;

Nov
24
1 month ago
Activity icon

Started a new Conversation How To Insert Validate With Javascript?

My form is like this , it may has manual social network

social network

I want to a user enter the id of channel, with @.

for example

May a user enter with URL, for example https://t.me/oxbir .

how to get validate with JavaScript?

I don't want to enter URL, I want to enter if of channel. @oxbir

blade

    function showDynamicSocial() {
        let html = '' +
            '@foreach(auth()->user()->socials as $social)\n'+
            '<div class="col-md-6 position-relative">\n' +
            '<i class="fas fa-times text-danger position-absolute"></i>' +
            '<div class="row">\n' +
            '<div class="col-md-4">\n' +
            '<div class="form-group">\n' +
            '<label for="social_id">Social Network</label>\n' +
            '<select id="social_id" name="social_id[]" class="form-control">\n' +
            '@foreach($socials as $socialData)\n'+
            '<option value="{{ $socialData->id }}" {{ $socialData->id == $social->id ? 'selected' : ''}}>\n'+
            '{{ $socialData->name }}\n' +
            '</option>\n' +
            '@endforeach\n' +
            '</select>\n' +
            '</div>\n' +
            '</div>\n' +
            '<div class="col-md-8">\n' +
            '<div class="form-group">\n' +
            '<label for="link">Profile ID</label>\n' +
            '<input id="link" value="{{ $social->pivot->link }}" name="link[]" class="form-control">\n' +
            '</div>\n' +
            '</div>\n' +
            '</div>\n' +
            '</div>\n ' +
            '@endforeach';
        $('#showSocial').append(html);
    }

javascript

$('div .btn-next').on('click', function() {
    var parent_fieldset = $(this).parents('fieldset');
    var next_step = true;
    var current_active_step = $(this).parents('div').find('.form-wizard.active');
    var progress_line = $(this).parents('div').find('.progress-line');
    if( next_step ) {
        parent_fieldset.fadeOut(400, function() {
            current_active_step.removeClass('active').addClass('activated').next().addClass('active');
            bar_progress(progress_line, 'right');
            alert('it is an error');
            $(this).next().fadeIn();
            scroll_to_class( $('.wizards'), 20 );
        });
    }

});
Activity icon

Started a new Conversation Checking Channel Id With JavaScript

My form is like this

socials

I want to a user enter the id of channel, with @.

for example

May a user enter with URL, for example https://t.me/oxbir .

how to get validate with JavaScript?

I don't want to enter URL, I want to enter if of channel. @oxbir

$('div .btn-next').on('click', function() {
    var parent_fieldset = $(this).parents('fieldset');
    var next_step = true;
    var current_active_step = $(this).parents('div').find('.form-wizard.active');
    var progress_line = $(this).parents('div').find('.progress-line');
    var first_name, text;
    // Get the value of the input field with id="numb"
    first_name = document.getElementById("first_name").value;

    // If x is Not a Number or less than one or greater than 10
    if (isNaN(first_name) || first_name < 1 || first_name > 10) {
        text = "enter only id.";
        next_step = false;
    }
    document.getElementById("alert_first_name").innerHTML = text;
    if( next_step ) {
        parent_fieldset.fadeOut(400, function() {
            current_active_step.removeClass('active').addClass('activated').next().addClass('active');
            bar_progress(progress_line, 'right');
            $(this).next().fadeIn();
            scroll_to_class( $('.wizards'), 20 );
        });
    }

});
Activity icon

Started a new Conversation How To Insert Validate With Javascrpt?

My form is like this

form

I added a validate in first_name. and I want to when if the first name is blank. it should show alert of bootstrap in near textbox of first_name

<div class="col-md-4">
    <div class="form-group">
        <label for="first_name">first_name</label>
        <input type="text" class="form-control" value="{{ auth()->user()->first_name }}" id="first_name" name="first_name">
        <div id="alert_first_name" class="mt-1 alert alert-danger alert-dismissible fade show d-none" role="alert">

            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
        </div>
    </div>
</div>

js

$('div .btn-next').on('click', function() {
    var parent_fieldset = $(this).parents('fieldset');
    var next_step = true;
    var current_active_step = $(this).parents('div').find('.form-wizard.active');
    var progress_line = $(this).parents('div').find('.progress-line');
    var first_name, text;
    // Get the value of the input field with id="numb"
    first_name = document.getElementById("first_name").value;

    // If x is Not a Number or less than one or greater than 10
    if (isNaN(first_name) || first_name < 1 || first_name > 10) {
        text = "It is required.";
        next_step = false;
    }
    document.getElementById("alert_first_name").innerHTML = text;
    if( next_step ) {
        parent_fieldset.fadeOut(400, function() {
            current_active_step.removeClass('active').addClass('activated').next().addClass('active');
            bar_progress(progress_line, 'right');
            $(this).next().fadeIn();
            scroll_to_class( $('.wizards'), 20 );
        });
    }

});
Nov
23
1 month ago
Activity icon

Replied to SQLSTATE[23000]: Integrity Constraint Violation

OK, When I make:auth I see this error.

error

Activity icon

Replied to SQLSTATE[23000]: Integrity Constraint Violation

I get this error.

SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value (SQL: insert into posts (title, body, updated_at, created_at) values (testt, test, 2020-11-24 01:15:08, 2020-11-24 01:15:08))

Activity icon

Replied to SQLSTATE[23000]: Integrity Constraint Violation

Post.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    protected  $guarded  = [
        'user_id',
        'title',
        'body',
    ];

    public function user()
    {
        return $this->belongsTo(User::class);
    }
}
Activity icon

Replied to SQLSTATE[23000]: Integrity Constraint Violation

@snapey

I get this message

array:4 [▼
    "_token" => "wducadsyWiF9ntyDbWWYHQchRkEJ8p3CakWmIKqe"
    "title" => "aaaaaaa"
    "body" => "aaaaaaaa"
    "category" => "1"
]

blade

<div class="p-5">
    <h3><i class="fas fa-plus-square mr-4 ml-1 mt-2"></i>create post</h3><hr>
    @include('Admin.layouts.alert')
    <form action="{{ route('posts.store') }}" method="POST">
        @csrf
        <div class="form-group">
            <label for="title">title</label>
            <input type="text" name="title" id="title" class="form-control">
        </div>
        <div class="form-group">
            <label for="body">body</label>
            <textarea name="body" id="body" class="form-control"></textarea>
        </div>
        <div class="form-group">
            <label for="category">category</label>
            <select name="category" id="category" class="form-control">
                @foreach($categories as $category)
                    <option value="{{ $category->id }}">{{ $category->name }}</option>
                @endforeach
            </select>
        </div>
        <div class="form-group">
            <button type="submit" class="btn btn-primary">save</button>
        </div>
    </form>
</div>

table

public function up()
{
    Schema::create('posts', function (Blueprint $table) {
        $table->id();
        $table->bigInteger('user_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        $table->string('title');
        $table->text('body');
        $table->timestamps();
    });
}
Activity icon

Replied to SQLSTATE[23000]: Integrity Constraint Violation

@talinon

I already added the following code in the Post.php model.

protected  $fillable = [
    'user_id',
    'title',
    'body',
];

@tray2

I get this message

array:4 [▼
    "_token" => "wducadsyWiF9ntyDbWWYHQchRkEJ8p3CakWmIKqe"
    "title" => "aaaaaaa"
    "body" => "aaaaaaaa"
    "category" => "1"
]
Activity icon

Started a new Conversation SQLSTATE[23000]: Integrity Constraint Violation

When I store my post , I get an error.

sql

Controller

public function store(Request $request)
{
    $post = Post::create([
        'user_id' => 1,
        'title' => $request->title,
        'body' => $request->body,
    ]);
    $post->categories()->attach($request->category);
}
Nov
22
1 month ago
Activity icon

Replied to Height 100vh Not Working

but i used pdf

Nov
21
1 month ago
Activity icon

Started a new Conversation Height 100vh Not Working

I want to create pdf with laravel. When I create a sidebar, It has need to height of 100%.

<!doctype html>
<html lang="fa">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
<div class="wrapper">
    <div class="col-300">
        <div class="card">
            <img src="{{ asset('images/avatar.png') }}">
        </div>
    </div>
    <div class="col-822"></div>
</div>
</body>
</html>

style.css

body {
    background-color: red;
    font-family: Tahoma;
}

.col-300 {
    width: 300px;
    background-color: blue;
    float: right;
    min-height: 100vh;
    height: auto !important;
}

.col-822 {
    width: 822px;
    height: 200px;
    float: left;
    background-color: green;
}

.card {
    padding: 50px;
}

.card img {
    width: 200px;
}

I see this demo.

pdf

Nov
19
1 month ago
Activity icon

Started a new Conversation How To Output PDF?

I installed https://github.com/niklasravnsborg/laravel-pdf package.

I want to output PDF like this and I want to output PDF from id of wrapper not body.

demo

But I see this output.

PDF

PDFController.php

<?php

namespace App\Http\Controllers;

use PDF;

class PDFController extends Controller
{
    public function index()
    {
        return view('Home.pdf');
    }

    public function download()
    {
        $pdf = PDF::loadView('Home.pdf');
        return $pdf->stream('document.pdf');
    }
}

pdf.blade.php

<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>رزومه</title>
    <link href="{{ asset('themes/css/pdf.css') }}" rel="stylesheet" />
    <link rel="stylesheet" href="{{ asset('themes/fontawesome/css/all.min.css') }}">
</head>
<body>
<div class="buttons">
    <a class="btn-success" href="{{ route('download') }}">دریافت رزومه</a>
</div>
<div id="wrapper">
    <div class="resume">
        <div class="left">
            <div class="img_holder">
                @if (auth()->user()->image)
                    <img src="{{ asset('storage/'. auth()->user()->image) }}">
                @else
                    <img src="{{ asset('images/avatar.png') }}">
                @endif
            </div>
            <div class="contact_wrap pb">
                <div class="title">
                    تماس
                </div>
                <div class="contact">
                    <ul>
                        @if (auth()->user()->mobile)
                            <li>
                                <div class="li_wrap">
                                    <div class="icon"><i class="fas fa-mobile-alt" aria-hidden="true"></i></div>
                                    <div class="text">{{ auth()->user()->mobile }}</div>
                                </div>
                            </li>
                        @endif
                        @if (auth()->user()->telephone)
                            <li>
                                <div class="li_wrap">
                                    <div class="icon"><i class="fas fa-phone" aria-hidden="true"></i></div>
                                    <div class="text">{{ auth()->user()->telephone }}</div>
                                </div>
                            </li>
                        @endif
                        <li>
                            <div class="li_wrap">
                                <div class="icon"><i class="fas fa-envelope" aria-hidden="true"></i></div>
                                <div class="text">{{ auth()->user()->email }}</div>
                            </div>
                        </li>
                        @if (auth()->user()->website)
                            <li>
                                <div class="li_wrap">
                                    <div class="icon"><i class="fab fa-weebly" aria-hidden="true"></i></div>
                                    <div class="text">{{ auth()->user()->website }}</div>
                                </div>
                            </li>
                        @endif
                        @if (auth()->user()->address)
                            <li>
                                <div class="li_wrap">
                                    <div class="icon"><i class="fas fa-map-signs" aria-hidden="true"></i></div>
                                    <div class="text">{{ auth()->user()->address }}</div>
                                </div>
                            </li>
                        @endif
                    </ul>
                </div>
            </div>


            @if (count(auth()->user()->skills))
                <div class="skills_wrap pb">
                    <div class="title">
                        مهارتها
                    </div>
                    <div class="skills">
                        <ul>
                            @foreach(auth()->user()->skills as $skill)
                                <li>
                                    <div class="li_wrap">
                                        <div class="text">{{ $skill->level * 20 }}</div>
                                        <div class="icon">{{ $skill->skill_name }}</div>
                                    </div>
                                </li>
                            @endforeach
                        </ul>
                    </div>
                </div>
            @endif

            @if (count(auth()->user()->socials))
                <div class="hobbies_wrap pb">
                    <div class="title">
                        شبکه های اجتماعی
                    </div>
                    <div class="hobbies">
                        <ul>
                            @foreach(auth()->user()->socials as $social)
                                @if ($social->pivot->social_id == 1)
                                    <li>
                                        <div class="li_wrap">
                                            <div class="icon"><i class="fab fa-linkedin"></i></div>
                                            <div class="text">{{ $social->pivot->link }}</div>
                                        </div>
                                    </li>
                                @endif
                                @if ($social->pivot->social_id == 2)
                                    <li>
                                        <div class="li_wrap">
                                            <div class="icon"><i class="fab fa-twitter"></i></div>
                                            <div class="text">{{ $social->pivot->link }}</div>
                                        </div>
                                    </li>
                                @endif
                                @if ($social->pivot->social_id == 3)
                                    <li>
                                        <div class="li_wrap">
                                            <div class="icon"><i class="fab fa-facebook-square"></i></div>
                                            <div class="text">{{ $social->pivot->link }}</div>
                                        </div>
                                    </li>
                                @endif
                                @if ($social->pivot->social_id == 4)
                                    <li>
                                        <div class="li_wrap">
                                            <div class="icon"><i class="fab fa-instagram-square"></i></div>
                                            <div class="text">{{ $social->pivot->link }}</div>
                                        </div>
                                    </li>
                                @endif
                                @if ($social->pivot->social_id == 5)
                                    <li>
                                        <div class="li_wrap">
                                            <div class="icon"><i class="fab fa-telegram"></i></div>
                                            <div class="text">{{ $social->pivot->link }}</div>
                                        </div>
                                    </li>
                                @endif
                            @endforeach
                        </ul>
                    </div>
                </div>
            @endif
        </div>
        <div class="right">
            <div class="header">
                <div class="name_role">
                    @if (auth()->user()->first_name)
                        <div class="name">
                            {{ auth()->user()->first_name }} {{ auth()->user()->last_name }}
                        </div>
                    @endif
                    @if (auth()->user()->job_title)
                        <div class="role">
                            {{ auth()->user()->job_title }}
                        </div>
                    @endif
                </div>
                <div class="about">
                    {{ auth()->user()->description }}
                </div>
                <div class="other">
                    <div>متولد: {{ auth()->user()->birth_date_year.'/'.auth()->user()->month_id.'/'.auth()->user()->birth_date_day }}</div>
                    <div>وضعیت تأهل: {{ auth()->user()->marital == 1 ? 'متاهل' : 'مجرد' }}</div>
                    @if (auth()->user()->soldier)
                        <div>وضعیت سربازی: {{ auth()->user()->soldier->name }}</div>
                    @endif
                </div>
            </div>
            <div class="right_inner">
                @if (count(auth()->user()->jobs))
                    <div class="jobs">
                        <div class="title">
                            سوابق شغلی
                        </div>
                        <div class="exp_wrap">
                            <ul>
                                @foreach(auth()->user()->jobs as $job)
                                    <li>
                                        <div class="li_wrap">
                                            <div class="date">
                                                {{ $job->start_year }} - @if ($job->starting) {{ $job->starting->name }} @endif
                                                <br>
                                                {{ $job->finish_year }} - @if ($job->finishing) {{ $job->finishing->name }} @endif
                                            </div>
                                            <div class="info">
                                                <p class="info_com">
                                                    سِمت شغلی مربوطه: {{ $job->job_position }}
                                                </p>
                                                @if ($job->group)
                                                    <p class="info_com">
                                                        گروه کاری: {{ $job->group->name }}
                                                    </p>
                                                @endif
                                                <p class="info_com">
                                                    شرکت: {{ $job->center_title }}
                                                </p>
                                                @if ($job->employment)
                                                    <p class="info_com">
                                                        مرکز اشتغال: {{ $job->employment->name }}
                                                    </p>
                                                @endif
                                                <p class="info_com">
                                                    شرکت: {{ $job->center_title }}
                                                </p>
                                                @if ($job->senior)
                                                    <p class="info_com">
                                                        سطح ارشدیت: {{ $job->senior->name }}
                                                    </p>
                                                @endif
                                                <p class="info_com">
                                                    کشور - استان - شهر:
                                                    @if (auth()->user()->land) {{ $job->land->name }} @endif -
                                                    @if (auth()->user()->shire) {{ $job->shire->name }} @endif -
                                                    @if (auth()->user()->parish) {{ $job->parish->name }} @endif
                                                </p>
                                            </div>
                                        </div>
                                    </li>
                                @endforeach
                            </ul>
                        </div>
                    </div>
                @endif
                @if (count(auth()->user()->educationals))
                    <div class="educations">
                        <div class="title">
                            سوابق تحصیلی
                        </div>
                        <div class="education_wrap">
                            <ul>
                                @foreach(auth()->user()->educationals as $educational)
                                    <li>
                                        <div class="li_wrap">
                                            <div class="date">
                                                {{ $educational->entrance }}
                                                <br>
                                                {{ $educational->graduate }}
                                            </div>
                                            <div class="info">
                                                <p class="info_com">
                                                    مقطع: {{ $educational->grade->name }}
                                                </p>
                                                <p class="info_com">
                                                    رشته تحصیلی: {{ $educational->field }}
                                                </p>
                                                <p class="info_com">
                                                    گرایش/تخصص: {{ $educational->branch }}
                                                </p>
                                                <p class="info_com">
                                                    نوع موسسه: {{ $educational->institution->name }}
                                                </p>
                                                <p class="info_com">
                                                    عنوان موسسه آموزشی: {{ $educational->institution_education }}
                                                </p>
                                                <p class="info_com">
                                                    معدل: {{ $educational->gpa }}
                                                </p>
                                                <p class="info_com">
                                                    کشور - استان - شهر:
                                                    @if (auth()->user()->nation)
                                                    {{ $educational->nation->name }} - {{ $educational->province->name }} - {{ $educational->town->name }}
                                                    @endif
                                                </p>
                                                <p class="info_com">
                                                    در حال تحصیل: {{ $educational->currently_studying == 1 ? 'بله' : 'خیر' }}
                                                </p>
                                            </div>
                                        </div>
                                    </li>
                                @endforeach
                            </ul>
                        </div>
                    </div>
                @endif
                @if (count(auth()->user()->certificates))
                    <div class="certificates">
                        <div class="title">
                            دوره‌ها و گواهینامه‌ها
                        </div>
                        <div class="certificate_wrap">
                            <ul>
                                @foreach(auth()->user()->certificates as $certificate)
                                    <li>
                                        <p class="info_com">
                                            نوع گواهینامه: {{ $certificate->c_type->name }}
                                        </p>
                                        <p class="info_com">
                                            عنوان: {{ $certificate->c_title }}
                                        </p>
                                        <p class="info_com">
                                            موسسه: {{ $certificate->c_institute }}
                                        </p>
                                        <p class="info_com">
                                            تاریخ: {{ $certificate->c_month->name }} - {{ $certificate->c_year }}
                                        </p>
                                    </li>
                                @endforeach
                            </ul>
                        </div>
                    </div>
                @endif
                @if (count(auth()->user()->honors))
                    <div class="honors">
                        <div class="title">
                            افتخارات
                        </div>
                        <div class="honor_wrap">
                            <ul>
                                @foreach(auth()->user()->honors as $honor)
                                    <li>
                                        <p class="info_com">
                                            موسسه: {{ $honor->institute_honor }}
                                        </p>
                                        <p class="info_com">
                                            تاریخ: {{ $honor->h_month->name }} - {{ $honor->h_year }}
                                        </p>
                                    </li>
                                @endforeach
                            </ul>
                        </div>
                    </div>
                @endif
                @if (count(auth()->user()->articles))
                    <div class="articles">
                        <div class="title">
                            تحقیقات و مقالات
                        </div>
                        <div class="article_wrap">
                            <ul>
                                @foreach(auth()->user()->articles as $article)
                                    <li>
                                        <p class="info_com">
                                            نوع اثر: {{ $article->effect->name }}
                                        </p>
                                        <p class="info_com">
                                            عنوان: {{ $article->article_title }}
                                        </p>
                                        <p class="info_com">
                                            ناشر: {{ $article->written }}
                                        </p>
                                        <p class="info_com">
                                            لینک مرتبط: {{ $article->article_link }}
                                        </p>
                                        <p class="info_com">
                                            تاریخ: {{ $article->article_month->name }} - {{ $article->article_year }}
                                        </p>
                                        <p class="info_com">
                                            توضیحات: {{ $article->article_description }}
                                        </p>
                                    </li>
                                @endforeach
                            </ul>
                        </div>
                    </div>
                @endif
                @if (count(auth()->user()->projects))
                    <div class="projects">
                        <div class="title">
                            افتخارات
                        </div>
                        <div class="project_wrap">
                            <ul>
                                @foreach(auth()->user()->projects as $project)
                                    <li>
                                        <p class="info_com">
                                            عنوان: {{ $project->project_title }}
                                        </p>
                                        <p class="info_com">
                                            کارفرما / درخواست کننده: {{ $project->project_employer }}
                                        </p>
                                        <p class="info_com">
                                            لینک مرتبط: {{ $project->project_link }}
                                        </p>
                                        <p class="info_com">
                                            تاریخ: {{ $project->project_month->name }} - {{ $project->project_year }}
                                        </p>
                                        <p class="info_com">
                                            نوضیحات: {{ $project->project_description }}
                                        </p>
                                    </li>
                                @endforeach
                            </ul>
                        </div>
                    </div>
                @endif
            </div>
        </div>
    </div>
</div>
</body>
</html>