YuraLons

Member Since 11 Months Ago

Experience Points
1,900
Total
Experience

3,100 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
2
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 1
1,900 XP
Apr
21
3 weeks ago
Activity icon

Replied to Doesn't List Streets And Houses

I did, but it does not display the name, there are no errors


    1 => App\Models\Fillable\Protocol {#1667 ▼
      #table: "protocols"
      #fillable: array:3 [ …3]
      #connection: "mysql"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:6 [ …6]
      #original: array:6 [ …6]
      #changes: []
      #casts: []
      #classCastCache: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: array:1 [ …1]
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #guarded: array:1 [ …1]
    }
Activity icon

Replied to Doesn't List Streets And Houses

I'm confused. Model Houses

<?php

namespace App\Models;

use App\Models\Fillable\Report;
use App\Models\Fillable\Dogovor;
use App\Models\Fillable\Protocol;
use App\Models\Fillable\Passport;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;

class Houses extends Model implements HasMedia
{
    use HasFactory, InteractsWithMedia;

    protected $table = 'house';

    protected $fillable = [
        'home_number',
        'street_id',
        'levels',
        'apps',
        's_nofull',
        's_life',
        's_full',
        'status',
        'year',
    ];

    public function street()
    {
        return $this->belongsTo(Street::class);
    }
    public function dogovor()
    {
        return $this->belongsTo(Dogovor::class);
    }
    public function protocols()
    {
        return $this->hasMany(Protocol::class);
    }

    public function registerMediaConversions(Media $media = null): void
    {
        $this->addMediaConversion('thumb')
            ->greyscale();
        $this->addMediaConversion('optimized');
        $this->addMediaConversion('non-optimized')
            ->nonOptimized();
    }

    public function getOtchetsForHouse()
    {
        return $this->hasMany(Otchet::class);
    }
    public function getDogovorsForHouse()
    {
        return $this->hasMany(Dogovor::class);
    }
    public function getProtocolsForHouse()
    {
        return $this->hasMany(Protocol::class);
    }
    public function getPassportsForHouse()
    {
        return $this->hasMany(Passport::class);
    }
}

Model Protocols

<?php

namespace App\Models\Fillable;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\Houses;

class Protocol extends Model
{
    use HasFactory;

    protected $table = 'protocols';

    protected $fillable = [
        'protocol_name',
        'protocol_link',
        'houses_id'
    ];


    public function house()
{
    return $this->belongsTo(Houses::class);
}
}

Controller [email protected]

        $protocols = Protocol::with('houses')->get();
        return view('dashboard.shouse.protocol.main', compact('protocols'));

View [email protected]

@foreach($protocols as $protocol)
                <tr class="h-10">
                    @foreach($protocol->houses as $house)
                        <td>{{$house->home_number}}</td>
                    @endforeach
                    <td width="60%" class="text-center">{{$protocol->protocol_name}}</td>
                    <td>
                        <a class="rounded py-1 px-2 bg-green-600 text-white" href="#">Изменить</a>
                        <a class="rounded py-1 px-2 bg-red-600 text-white" href="#">Удалить</a>
                    </td>
                </tr>
            @endforeach
Activity icon

Replied to Doesn't List Streets And Houses

I changed model protocol return $this->belongsTo(Houses::class); and model House return $this->hasMany(Protocol::class); In the controller indicated

$protocol = Protocol::with('houses')->get();

In the view indicated

@foreach($protocols as $protocol)
   <tr class="h-10">
@foreach($protocols->houses as $house)
   <td>{{$house->home_number}}</td>
@endforeach
   <td width="60%" class="text-center">{{$protocol->protocol_name}}</td>

And got a new error

ErrorException
Attempt to read property "home_number" on bool (View: D:\loc\testes\resources\views\dashboard\shouse\protocol\main.blade.php)
Activity icon

Replied to Doesn't List Streets And Houses

As I understand it, he is trying to find the protocol column in the table with houses.

And I don't have such a field there, that's why it gives an error.

table house

|   id   |   home_number   | other |

table Protocols

|   id   |   protocol_name   |   protocol_id   |   house_id   |

I have tables made this way When filling out the protocols, the house id is selected, and inserted into the house_id cell

Activity icon

Replied to Doesn't List Streets And Houses

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'house.protocol_id' in 'where clause' (SQL: select * from `house` where `house`.`protocol_id` in (16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
<tr class="h-10">
                    @foreach($protocols->houses as $house)
                        <td>{{$house->home_number}}</td>
                    @endforeach
                    <td width="60%" class="text-center">{{$protocol->protocol_name}}</td>
Activity icon

Started a new Conversation Doesn't List Streets And Houses

I'm trying to get the data for the administrative page to which house the protocol belongs to (on the protocols page). Created a function protocolMain

$protocols = Protocol::all();
$houses = $protocol->houses()->get;
return #code compact('protocols', 'houses');

Created a model in Protocol.php

public function houses()
    {
        return $this->HasMany(Houses::class);
    }

Created a model in House.php

public function protocols()
    {
        return $this->belongsTo(Protocol::class);
    }

But it displays an error

BadMethodCallException
Method Illuminate\Database\Eloquent\Collection::houses does not exist.

Where did I make the fatal mistake that led to the crash? The fact is that the table that I create has three fields (name, link, house_id), in the table house (house_number, street_id), in the table street (name) I wanted to display the following information in a table in a view / street, house / name of the protocol / actions with the file (buttons). But first I would like to get a list of houses to which the files belong

Apr
19
3 weeks ago
Activity icon

Replied to How Can I Edit Fields From Another Data Table?

great, tomorrow I won't get a blow on the head from the director). Thank you so much for your help and I apologize for taking the time to solve my problems.

Activity icon

Replied to How Can I Edit Fields From Another Data Table?

edit blade.php

@extends('index')

@section('content')

<div align="center">
<form method="post" action="{{ route('house.update', ['house' => $house->id]) }}">
    @csrf
    @method('PUT')
    <div>
        <label for="name">name</label>
        <input type="text" name="name" value="{{ $house->name }}">
    </div>
    <div>
        <label for="">description </label>
        <input type="text" name="description" value="{{ $house->description }}">
    </div>
    <div>
        <label for="">Passports</label>
		@foreach ($house->getPassportsForHouse as $passport)
	        <input type="text" name="passport[$passport->id][passport_name]" value="{{ $passport->passport_name }}">
	        <input type="text" name="passport[$passport->id][passport_link]" value="{{ $passport->passport_link }}">
		@endforeach
    </div>
<div>
        <label for="">dogovor</label>
		@foreach ($house->getDogovorsForHouse as $dogovor)
	        <input type="text" name="dogovor[$dogovor->id][dogovor_name]" value="{{ $dogovor->dogovor_name }}">
	        <input type="text" name="dogovor[$dogovor->id][dogovor_link]" value="{{ $dogovor->dogovor_link }}">
		@endforeach
    </div>
<div>
        <label for="">Othcet</label>
            @foreach ($house->getOtchetsForHouse as $otchet)
                <input type="text" name="otchet[$otchet->id][otchet_name]" value="{{ $otchet->otchet_name }}">
                <input type="text" name="otchet[$otchet->id][otchet_link]" value="{{ $otchet->otchet_link }}">
            @endforeach
    </div>
<div>
        <label for="">Protocols</label>
		@foreach ($house->getProtocolsForHouse as $protocol)
	        <input type="text" name="protocol[$protocol->id][protocol_name]" value="{{ $protocol->protocol_name }}">
	        <input type="text" name="protocol[$protocol->id][protocol_link]" value="{{ $protocol->protocol_link }}">
		@endforeach
    </div>
    <button type="submit">Save</button>
</form>
</div>

@endsection
Activity icon

Replied to How Can I Edit Fields From Another Data Table?

show.blade.php or edit.blade.php ?

Activity icon

Replied to How Can I Edit Fields From Another Data Table?

As I understand it now, there is an error in the date fields in the reports, contracts, protocols and passports tables ?

SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect DOUBLE value: '$passport->id' (SQL: update `passports` set `passport_name` = Passport 2 UPD, `passport_link` = Link passport 2 UPD, `passports`.`updated_at` = 2021-04-19 15:17:40 where `passports`.`house_id` = 2 and `passports`.`house_id` is not null and `id` = $passport->id)
Activity icon

Replied to How Can I Edit Fields From Another Data Table?

As far as I can understand, it tries to update several records, but it can't, it only issues an update of the second field

Activity icon

Replied to How Can I Edit Fields From Another Data Table?

array:8 [▼
  "_token" => "cPsdUSvu8k4Py713OOId2xUAyroFFqWkQ3ApVvqL"
  "_method" => "PUT"
  "name" => "Test new house UPD"
  "description" => "Description house test"
  "passport" => array:1 [▼
    "$passport->id" => array:2 [▼
      "passport_name " => "Passport 2"
      "passport_link" => "Link passport 2 UPD"
    ]
  ]
  "dogovor" => array:1 [▼
    "$dogovor->id" => array:2 [▼
      "dogovor_name " => "Dogovor 2 UPD"
      "dogovor_link" => "Link dogovor2"
    ]
  ]
  "otchet" => array:1 [▼
    "$otchet->id" => array:2 [▼
      "otchet_name" => "Report 2 UPD"
      "otchet_link" => "Link Report 2"
    ]
  ]
  "protocol" => array:1 [▼
    "$protocol->id" => array:2 [▼
      "protocol_name" => "Protocol 2"
      "protocol_link" => "Link protocol 2 UPD"
    ]
  ]
Activity icon

Replied to How Can I Edit Fields From Another Data Table?

I add dump($request()->all()); but I still have the same error on the page. Added like this

function update(Request $request, $id)
    {
        $house = House::findOrFail($id);
        $house->name                 =   $request->get('name');
        $house->description          =   $request->get('description');
        
       // #code

        dump($request()->all());
        // return redirect()->route('house.index');
    }

All the migrations that were added in the first post are exactly the same as those that I use.

Activity icon

Replied to How Can I Edit Fields From Another Data Table?

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'passport_name ' in 'field list' (SQL: update `passports` set `passport_name ` = $house->save();, `passport_link` = $house->save();, `passports`.`updated_at` = 2021-04-19 13:34:37 where `passports`.`house_id` = 1 and `passports`.`house_id` is not null and `id` = $passport->id)
Activity icon

Replied to How Can I Edit Fields From Another Data Table?

Added a full controller to the first post

Activity icon

Replied to How Can I Edit Fields From Another Data Table?

Damn - for sure, my fault .. I forgot myself that these fields are not there, but even after deleting these fields, the error remained in place

Activity icon

Replied to How Can I Edit Fields From Another Data Table?

A new error, but now all the fields are filled in as needed, the entire list of fields that I filled out for the house is displayed, but after editing the following:

lluminate\Database\QueryException
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'getOtchetsForHouse' in 'field list' (SQL: update `houses` set `name` = Test house, `description` = Test house, `getOtchetsForHouse` = ?, `getProtocolsForHouse` = ?, `getPassportsForHouse` = ?, `getDogovorsForHouse` = ?, `houses`.`updated_at` = 2021-04-19 13:25:49 where `id` = 1)
Activity icon

Replied to How Can I Edit Fields From Another Data Table?

Okay, I'll watch the video, but after I solve the problem with editing the fields in the cards at home, as now our company is suffering from this problem. I apologize for the inconvenience

Activity icon

Replied to How Can I Edit Fields From Another Data Table?

As I understand it, everything refers to blade files. The stack is the first to display error 95 line in the file Foundation \ Bootstrap \ HandleExceptions :: handleError, $iteratee = trim ($matches [1]); Then all the mistakes are repeated Illuminate\View\Compilers\BladeCompiler::compileStatements

Activity icon

Replied to How Can I Edit Fields From Another Data Table?

I got an error while editing at home ErrorException Undefined array key 1

Activity icon

Replied to How Can I Edit Fields From Another Data Table?

That is, as I understand it, the code is referring directly to the table? It's just that my model has four belongsTo getPassportForHouse getDogovorsForHuse getReportForHouse getProtocolForHouse. On creation, I refer to them this way:

foreach($request->get('passport_name') as $key => $passportName) {
            $house->getPassportsForHouse()
            ->create([
                'passport_name' => $passportName,
                'passport_link' => data_get($request->get('passport_link'), $key),
            ]);
        }

And if I understand correctly, then the model you have given can be changed somehow so that later you will not be confused where and where there was no mess in the code

function update(Request $request, $id)
{
	$house = House::findOrFail($id);
	/// code#
	$house->getOtchetForHouse = $request->get('otchet_name');
	$house->getOtchetForHouse = $request->get('otchet_link');
	$house->getProtocolForHouse = $request->get('protocol_name');
	$house->getProtocolForHouse = $request->get('protocol_link');
	$house->getPassportForHouse= $request->get('passport_name');
	$house->getPassportForHouse= $request->get('passport_link');
	$house->getDogovorForHouse= $request->get('dogovor_name');
	$house->getDogovorForHouse= $request->get('dogovor_link');

	$house->save();

	foreach ($request->get('passport', []) as $passportId => $passportAttributes) {
		$house->getPassportForHouse()->where('id', $passportId)->update($passportAttributes);
	}
foreach ($request->get('otchet', []) as $otchetId => $otechetAttributes) {
		$house->getOtchetForHouse ()->where('id', $otchetId)->update($otechetAttributes);
	}
foreach ($request->get('dogovor', []) as $dogovorId => $dogovorAttributes) {
		$house->getDogovorForHouse()->where('id', $dogovorId)->update($dogovorAttributes);
	}
foreach ($request->get('protocol', []) as $protocolId => $protocolAttributes) {
		$house->getProtocolForHouse ()->where('id', $protocolId)->update($protocolAttributes);
	}

View

<div>
        <label for="">Passports</label>
		@foreach ($house->getPassportForHouse as $passport)
	        <input type="text" name="passport[$passport->id][passport_name ]" value="{{ $passport->passport_name }}">
	        <input type="text" name="passport[$passport->id][passport_link]" value="{{ $passport->passport_link}}">
		@endforeach
    </div>
<div>
        <label for="">dogovor</label>
		@foreach ($house->getDogovorForHouseas $dogovor)
	        <input type="text" name="dogovor[$dogovor->id][dogovor_name ]" value="{{ $dogovor->dogovor_name }}">
	        <input type="text" name="dogovor[$dogovor->id][dogovor_link]" value="{{ $dogovor->dogovor_link}}">
		@endforeach
    </div>
<div>
        <label for="">Othcet</label>
		@foreach ($house->getOtchetForHouse as $otchet)
	        <input type="text" name="otchet[$otchet->id][otchet_name ]" value="{{ $otchet->otchet_name }}">
	        <input type="text" name="otchet[$otchet->id][otechet_link]" value="{{ $otchet->otechet_link}}">
		@endforeach
    </div>
<div>
        <label for="">Protocols</label>
		@foreach ($house->getProtocolForHouse as $protocol)
	        <input type="text" name="protocol[$protocol->id][protocol_name]" value="{{ $protocol->protocol_name}}">
	        <input type="text" name="protocol[$protocol->id][protocol_link]" value="{{ $protocol->protocol_link}}">
		@endforeach
    </div>

Is the given code correct? or contains errors?

Activity icon

Replied to How Can I Edit Fields From Another Data Table?

I didn't understand much of your question. I will answer in terms of my guesses He should receive a list of passports in which the home_id field has the id of the house being edited.

Model Passport

use App\Models\House;

class Passport extends Model
{
    use HasFactory;

    protected $table = 'passports';

    protected $fillable = [
        'passport_name',
        'passport_link'
    ];

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

Started a new Conversation How Can I Edit Fields From Another Data Table?

FullController House

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\House;
use App\Models\Otchet;
use Validate;

class HouseController extends Controller
{
    function index()
    {
        $houses = House::all();
        return view('house.list', compact('houses'));
    }
    public function show($id)
    {
        $house = House::with(['getOtchetsForHouse','getDogovorsForHouse','getProtocolsForHouse','getPassportsForHouse'])->find($id);
        $house->getOtchetsForHouse;
        $house->getDogovorsForHouse;
        $house->getProtocolsForHouse;
        $house->getPassportsForHouse;
        
        return view('house.show', compact('house'));
    }
    function create(Request $request)
    {
        return view('house.create');
    }
    function store(Request $request)
    {
        $this->validate($request, [
            'name'=>'required',
        ]);

        $house = House::query()->create([
            'name' => $request->get('name'),
            'description' => $request->get('description'),
        ]);
       
        // foreach($request->getOtchetsForHouse as $index => $otchets) {

        //     $house->otchets()->create([
        //         'file_name' => $otchet['file_name'],
        //         'link_file' => $otchet['link_file'],
        //      ]);

        // }

        // $house->getOtchetsForHouse()->
        // create([
        //     'otchet_name' => $request->get('otchet_name'),
        //     'otchet_link' => $request->get('otchet_link')
        // ]);
        // $house->getDogovorsForHouse()->
        // create([
        //     'dogovor_name' => $request->get('dogovor_name'),
        //     'dogovor_link' => $request->get('dogovor_link')
        // ]);
        // $house->getProtocolsForHouse()->
        // create([
        //     'protocol_name' => $request->get('protocol_name'),
        //     'protocol_link' => $request->get('protocol_link')
        // ]);
        // $house->getPassportsForHouse()->
        // create([
        //     'passport_name' => $request->get('passport_name'),
        //     'passport_link' => $request->get('passport_link')
        // ]);


        foreach($request->get('otchet_name') as $key => $otchetName) {
            $house->getOtchetsForHouse()
            ->create([
                'otchet_name' => $otchetName,
                'otchet_link' => data_get($request->get('otchet_link'), $key),
            ]);
        }
        foreach($request->get('dogovor_name') as $key => $dogovorName) {
            $house->getDogovorsForHouse()
            ->create([
                'dogovor_name' => $dogovorName,
                'dogovor_link' => data_get($request->get('dogovor_link'), $key),
            ]);
        }
        foreach($request->get('protocol_name') as $key => $protocolName) {
            $house->getProtocolsForHouse()
            ->create([
                'protocol_name' => $protocolName,
                'protocol_link' => data_get($request->get('protocol_link'), $key),
            ]);
        }
        foreach($request->get('passport_name') as $key => $passportName) {
            $house->getPassportsForHouse()
            ->create([
                'passport_name' => $passportName,
                'passport_link' => data_get($request->get('passport_link'), $key),
            ]);
        }

        dd($request->all());

        // return redirect()->route('house.index');
    }
    function edit(Request $request, $id)
    {
        $house = House::find($id);
        return view('house.edit', compact('house'));
    }
    function update(Request $request, $id)
    {
        $house = House::findOrFail($id);
        $house->name                 =   $request->get('name');
        $house->description          =   $request->get('description');
        
        $house->save();
        foreach ($request->get('passport', []) as $passportId => $passportAttributes) {
            $house->getPassportsForHouse()->where('id', $passportId)->update($passportAttributes);
            }
        foreach ($request->get('otchet', []) as $otchetId => $otchetAttributes) {
            $house->getOtchetsForHouse()->where('id', $otchetId)->update($otchetAttributes);
        }
        foreach ($request->get('dogovor', []) as $dogovorId => $dogovorAttributes) {
            $house->getDogovorsForHouse()->where('id', $dogovorId)->update($dogovorAttributes);
        }
        foreach ($request->get('protocol', []) as $protocolId => $protocolAttributes) {
            $house->getProtocolsForHouse()->where('id', $protocolId)->update($protocolAttributes);
        }
        return redirect()->route('house.index');
    }
}
function update(Request $request, $id)
    {
        $house = House::findOrFail($id);
        $house->name            =   $request->get('name');
        $house->description     =   $request->get('description');
        $house->getOtechetForHouse = $request->get('otchet_name');
        $house->getOtechetForHouse = $request->get('otechet_link');

        $house->save();
        return redirect()->route('house.index');
    }

view

<div align="center">
<form method="post" action="{{ route('house.update', ['house' => $house->id]) }}">
    @csrf
    @method('PUT')
    <div>
        <label for="name">Name</label>
        <input type="text" name="name" value="{{ $house->name }}">
    </div>
    <div>
        <label for="">Description</label>
        <input type="text" name="description" value="{{ $house->description }}">
    </div>
    <div>
        <label for="">Report</label>
        <input type="text" name="otchet_name" value="{{ $house->otchet_name }}">
    </div>
    <button type="submit">Save</button>
</form>
</div>

Everything works in the controller, all data is displayed according to the ID of the house, but here's the problem with getting data that is outside the house table, I have 4 tables that are connected via hasMany, there are no problems with adding, but there were big problems with editing. I tried to output through: $house -> getPassportsForHouse = $request -> get('passport_name'); It just did not show anything, in principle, there is nothing surprising in this. The table looks like this: passport table

 Schema::create('passports', function (Blueprint $table) {
            $table->id();
            $table->text('passport_name');
            $table->text('passport_link');
            $table->unsignedBigInteger('house_id')->index();
            $table->foreign('house_id')->references('id')->on('houses');
            $table->timestamps();
        });

house table

Schema::create('houses', function (Blueprint $table) {
            $table->id();
            $table->string('name')->nullable();
            $table->text('description')->nullable();
            $table->timestamps();
        });

How to correctly add the code so that I can edit the records belonging to the house in the tables passport, contract, report, protocols

Activity icon

Replied to Error When Trying To Add Multiple Data To The Database

OH, I found an error, for some reason I wrote a dash for the place of equality in date_get

Activity icon

Replied to Error When Trying To Add Multiple Data To The Database

 foreach($request->get('otechet_name') as $key => $otchetName) {
            $house->getOtechetForHouse()
            ->create([
                'otchet_name' => $otchetName,
                'otchet_link' ->data_get($request->get('otchet_link'), $key),
            ]);
        }
        foreach($request->get('dogovor_name') as $key => $dogovorName) {
            $house->getDogovorsForHouse()
            ->create([
                'dogovor_name' => $dogovorName,
                'dogovor_link' ->data_get($request->get('dogovor_link'), $key),
            ]);
        }
        foreach($request->get('protocol_name') as $key => $protocolName) {
            $house->getProtocolsForHouse()
            ->create([
                'protocol_name' => $protocolName,
                'protocol_link' ->data_get($request->get('protocol_link'), $key),
            ]);
        }
        foreach($request->get('passport_name') as $key => $passportName) {
            $house->getPassportsForHouse()
            ->create([
                'passport_name' => $passportName,
                'passport_link' ->data_get($request->get('passport_link'), $key),
            ]);
        }

The result is the following code, but how can I bring it into view now? Or a view that I already have suitable for use? An error has occurred now

Error
Call to a member function data_get() on string
Activity icon

Started a new Conversation Error When Trying To Add Multiple Data To The Database

The controller contains the following code:

$house = House::query()->create([
            'name' => $request->get('name'),
            'description' => $request->get('description'),
        ]);

        $house->getReportsForHouse()->
        create([
            'otchet_name' => $request->get('report_name'),
            'otchet_link' => $request->get('report_link')
        ]);
        $house->getDogovorsForHouse()->
        create([
            'dogovor_name' => $request->get('dogovor_name'),
            'dogovor_link' => $request->get('dogovor_link')
        ]);
        $house->getProtocolsForHouse()->
        create([
            'protocol_name' => $request->get('protocol_name'),
            'protocol_link' => $request->get('protocol_link')
        ]);
        $house->getPassportsForHouse()->
        create([
            'passport_name' => $request->get('passport_name'),
            'passport_link' => $request->get('passport_link')
        ]);

        dd($request->all());

views

<div class="report" align="center" style="padding-bottom: 10px;">
        <button class="Report_add" type="button">Add Report</button>
        
        <div>
            <label for="getReportsForHouse">Report</label>
                <input type="text" id="otchet_name" name="report_name[]">
                <input type="text" id="otchet_link" name="report_link[]">
        </div>
    </div>

When adding one object to the fields, dd returns the following

array:11 [▼
  "_token" => "PCOMOlKj7WcnDkON8u6ScEQkFSuz4ThPRFkPscXK"
  "name" => "House 1"
  "description" => "Descr house"
  "report_name" => "report1"
  "report_link" => "report_link"
  "dogovor_name" => "dogovor_name1"
  "dogovor_link" => "dogovor_link"
  "passport_name" => "passport_name1"
  "passport_link" => "passport_link1"
  "protocol_name" => "protocol_name1"
  "protocol_link" => "protocol_link"
]

Everything is successfully added, but when I try to add multiple items, I get an error

TypeError Illuminate\Database\Grammar::parameterize(): Argument #1 ($values) must be of type array, int given, called in 
D:\loc\testehouse\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php on line 886

If you remove the brackets and try to add several objects, the last object from the created list will be added.

How to add multiple elements at once in a given controller and view ?

Apr
18
3 weeks ago
Activity icon

Replied to Several Objects Are Not Added At The Same Time

Controller

$house->getReportsForHouse()->create([
            'file_name' => $request->get('file_name'),
            'link_file' => $request->get('link_file')
        ]);
        $house->getDogovorsForHouse()->create([
            'file_name' => $request->get('file_name'),
            'link_file' => $request->get('link_file')
        ]);
        $house->getProtocolsForHouse()->create([
            'file_name' => $request->get('file_name'),
            'link_file' => $request->get('link_file')
        ]);
        $house->getPassportsForHouse()->create([
            'file_name' => $request->get('file_name'),
            'link_file' => $request->get('link_file')
        ]);

All fields are filled in well, but when I need to add a field for something else, for example for reports, then I immediately throw an error

Activity icon

Started a new Conversation Several Objects Are Not Added At The Same Time

I am trying to add several objects to the record, but an error occurs

Illuminate\Database\Grammar::parameterize(): Argument #1 ($values) must be of type array, int given, called in D:\loc\testehouse\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php on line 886

But if I remove the square brackets in the view, then everything works, but adds only the last entry that I made

Create blade php

<div>
   <label for="getReportsForHouse">Report</label>
      <input type="text" id="file_name" name="file_name[]">
      <input type="text" id="link_file" name="link_file[]">
</div>

*script*

$(".report").append(
              `<div>
   <label for="getReportsForHouse">Report</label>
      <input type="text" id="file_name" name="file_name[]">
      <input type="text" id="link_file" name="link_file[]">
</div>`
            );
Apr
16
4 weeks ago
Activity icon

Replied to How To Correctly Draw Up A Form When Filling Out An Entry?

But I get data in the show method. But there I have a code like this

$post = Post::with([... , getNameStoreForPost, ....])
$post->getNamesStoreForPost;

return view('post.show, compact('post'));

My question is how to correctly make a function to add these fields, the post itself is created, but the fields are not filled

Activity icon

Started a new Conversation How To Change Fields From File Type To Text Type?

There is a code like this, which is located in

public function store() {
// #code


if ($request->hasFile('passport'))
        {
            foreach($request->file('passport') as $index => $passport){
                $name = ($request->passport_name[$index]). '.' .$passport->getClientOriginalExtension();
                $str_passport = $passport->storeAs('passport', $name, 'public');
                $homes->passportDocuments()->create([
                    'document' => $str_passport,
                    'document_name' => $name,
                ]);
            }
        }
}.

With it, I can load files into the database and call them by my name. In fact, these are two tables, the projects table and the passport table, they are linked in the models using (belongsTo & hasMany). But how can I turn these fields into text fields? so that I for the place of files and indicating their name in the project, indicate the link to the file and the name of this link? That is, I have now connected a passport_link table with four fields (id, file_name, file_link, project_id). At the moment, I was able to display the data that I filled in manually, but when I tried to create data in the

function store (Request $request) {
// code ....

$project->getPassportForHouse->create (
'name' => $request->get('file_name),
'file_link' => $request->get('file_link')
}

I'm getting an error

BadMethodCallException Method Illuminate\Database\Eloquent\Collection::create does not exist.
Activity icon

Replied to How To Correctly Draw Up A Form When Filling Out An Entry?

I changed the data in the method, and also set square brackets when adding a store. But I still can't add a store to the post card.

Activity icon

Replied to How To Correctly Draw Up A Form When Filling Out An Entry?

It's name function in model Post.

 public function getNameStoreForPost()
    {
        return $this->hasMany(Store::class);
    }
Apr
15
4 weeks ago
Activity icon

Started a new Conversation How To Correctly Draw Up A Form When Filling Out An Entry?

How do I correctly add fields from a post form to other tables? I have a post table containing records, it is necessary to specify data in 4 other tables (store1, store2, store3, store4).

I thought I should do it this way:

[email protected]

function store(Request $request)
    {
        $this->validate($request, [
            'name'=>'required',
            'description'=>'required'
        ]);


        $post = Post::query()->create(
            $request->all()
        );
        $post->getNameStoreForPost()->create([
            $request->all()
        ]);

        return redirect()->route('posts.index');
    }

MyPostCreateForm


<form method="post" action="{{ route('posts.store') }}">
    @csrf
    <div align="center">
        <div style="padding-bottom: 25px;">
            <label for="name">Post Name</label>
            <input type="text" name="name" id="name">
        </div>
        <div style="padding-bottom: 25px;">
            <label for="description">Description post</label>
            <input type="text" name="description" id="description">
        </div>
    </div>

    <div class="store" style="padding-bottom: 10px;">
        <button class="store_add" type="button">Add store</button>
        <br>
        <br>
        <div>
            <label for="getNameStoreForPost">Links</label>
                <input type="text" id="store_name" name="store_name">
                <input type="text" id="store_link" name="store_link">
        </div>
    </div>
    <button type="submit">Add post</button>
</form>
@endsection

@push('script')
$(document).ready(function () {
        $(".store_add").on('click',function(){
            $(".store").append(
              `<div>
            <label for="getNameStoreForPost">Links</label>
                <input type="text" id="store_name" name="store_name">
                <input type="text" id="store_link" name="store_link">>
        </div>`
            );
        });
        
    });
@endpush

But when creating, I get an error 1364, the field is not post_id is not filled in, and cannot be empty by default.

I think that the error is in the controller, since I set the name and title of the link, but it does not add it because the field with the post is not indicated where. How do I fix the error?

Thanks in advance!

Apr
02
1 month ago
Activity icon

Started a new Conversation PostCSS Does Nothing.

Yesterday, when PhpStorm was closed, everything worked fine, the project was going as it should. Now when I opened the project again and received the message:

You have not installed any plugins, parser or stringifier. PostCSS is not doing anything right now. Select plugins for your case at https://www.postcss.parts/ and use them in postcss.config.js.

I decided to revise the project, reinstalled all modules (using TailwindCss). I did everything as in the documentation, but I still get this message, while the project shows that it is fully assembled.

What other modules does he need, and why didn't I receive these messages yesterday?

Mar
27
1 month ago
Activity icon

Replied to How To Add The Name Of The Uploaded File In The Controller ?

I found this article in the documentation https://laravel.com/docs/8.x/filesystem#specifying-a-file-name. As I understand it, I need to add to the line

$str_passport = $passport->storeAs('passport', 'document_name', 'public');

And in the form itself, specify an additional field

<div class="passport_list">
  <button class="add_passport" type="button">Add passport</button><br><br>
     <div>
        <label for="passport">Passport</label>
          <input class="w-1/2" type="file" name="passport[]">
          <input class="w-1/2" type="text" name="document_name" placheholder="Name download file">
     </div>
</div>

Right? Or am I wrong somewhere

Activity icon

Started a new Conversation How To Add The Name Of The Uploaded File In The Controller ?

In the migration, I created a field with the name of the document, in the model I also registered it in the filled fields. How can I enter my names for them in the form when uploading files? Controller @ store

 if ($request->hasFile('passport'))
        {
            foreach($request->file('passport') as $passport){
                $str_passport = $passport->store('passport', 'public');
                $homes->passportDocuments()->create(['document' => $str_passport]);
            }
        }

Model Passport

protected $fillable = [
        'document',
        'document_name',
    ];

    public function house()
    {
        return $this->belongsTo(Houses::class);
    }

My view (created)

<div class="passport_list">
  <button class="add_passport" type="button">Add passport</button><br><br>
     <div>
        <label for="passport">Passport</label>
          <input class="w-full" type="file" name="passport[]">
     </div>
</div>
Mar
26
1 month ago
Activity icon

Started a new Conversation Changing The Name Of A File While Downloading It

Is it possible to indicate its name when loading a file in order to display it in its proper place in the future? I have several different files per project, I did not work with the automatic naming system, since only the file ID was displayed and that's it. I would like to make sure that when I enter the house card I have a grouped list of files with the names that I will give them myself. Migrate File Table (passport)

public function up()
    {
        Schema::create('passports', function (Blueprint $table) {
            $table->id();
            $table->string('document');
            $table->integer('houses_id');
            $table->timestamps();
        });
    }

As I understand it, it is necessary to press the field

$table->string('fileName');

But I do not understand how I can do it in the controller so that I can name the files myself as I want (when loading them).

HomeController @ store download file

if ($request->hasFile('passport'))
        {
            foreach($request->file('passport') as $passport){
                $str_passport = $passport->storeAs('passport',  $homes->id . ' - ' . $homes->passport . ' - ' . $homes->date, 'public');
                $homes->passportDocuments()->create(['document' => $str_passport]);
            }
        }

created.blade.php

 $(".add_passport").on('click',function(){
    $(".passport_list").append(
    `<div> <label for="passport">Passport house</label>
<input class="w-full" type="file" name="passport[]"> </div>`
    );
    });

How and where can I add a field to fill in the file name?

Activity icon

Replied to How Do I Change The Name Of A File When Uploading It?

My files seem to be loading correctly, but they are not defined as an extension, that is, it looks like this now (id - [] - -) and the link itself leads to the 404 page, for the location of the file download. I can add an extra field to the title table, right? so that I can fill in the file name myself and upload it to the site?

Mar
25
1 month ago
Activity icon

Replied to Transferring Laravel 8 To The VPS Server

Its Work, Thanks !

Mar
24
1 month ago
Activity icon

Replied to Transferring Laravel 8 To The VPS Server

<VirtualHost *:80>
/////
/////
/////
DocumentRoot /var/www/laravel/public  ????
/////
/////
/////
</VirtualHost>

or

<Directory /var/www/laravel/public>
/////
/////
/////
Activity icon

Replied to Transferring Laravel 8 To The VPS Server

etc/apache2/sites-available/domain.conf

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName domain
    ServerAlias www.domain
    DocumentRoot /var/www/laravel
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Of course - for the place of the domain I have a link to my site. or do you need another file?

Activity icon

Started a new Conversation Transferring Laravel 8 To The VPS Server

I started to transfer Laravel to VPS, after all the manipulations I have two problems:

I can't understand why .htaccess does not work, there I registered the paths to the public folder, so that when you enter the site address, it will be displayed immediately.

More than one route does not work. I have routes (about, contacts, streets, houses, information, and dashboard), not one does not answer, error 404, and what is the error from apache, not from laravel. What I did :

  1. art route:clear
  2. art cache:clear
  3. art config:clear
  4. composer update
Mar
22
1 month ago
Activity icon

Replied to How Do I Change The Name Of A File When Uploading It?

i'm us Windows 10 ) It's my local machine

Activity icon

Replied to How Do I Change The Name Of A File When Uploading It?

fopen(D:\local\untitled\storage\app/public\passport/6 - - ): Failed to open stream: Permission denied

What rights does he need?

Activity icon

Started a new Conversation How Do I Change The Name Of A File When Uploading It?

How to make sure that using this function the documents are uploaded to the folder with the home ID? And how to change the file name from this one (E0FIfjmuAbTV9Nhol2Q31lRNBbJZpL1ZHhZ3VK4R.pdf), to (house id - contract - date)

if ($request->hasFile('passport'))
        {
            foreach($request->file('passport') as $passport){
                $str_passport = $passport->store('passport','public');
                $homes->passport()->create(['document' => $str_passport]);
            }
        }
Activity icon

Replied to Outputting Files To The View From The Database

That is, now I just need to remove the columns with file uploads from the migration and display them as I did with the passport?

Activity icon

Replied to Outputting Files To The View From The Database

But when I create a card at home, my house is not filled in the table (fields contract, report, protocol, passport), they are all in their tables, and have their own paths

Activity icon

Replied to Outputting Files To The View From The Database

Houses Model

<?php

namespace App\Models;

use App\Models\Docs\Contract;
use App\Models\Docs\Report;
use App\Models\Docs\Passport;
use App\Models\Docs\Protocol;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;

class Houses extends Model implements HasMedia
{
    use HasFactory, InteractsWithMedia;

    protected $table = 'house';

    protected $fillable = [
        'home_number',
        'street_id',
        'option',
        'apparts',
        's_full',
        's_life',
        's_nolife',
        'status',
        'year',
    ];

    public function street()
    {
        return $this->belongsTo(Street::class);
    }

    public function registerMediaConversions(Media $media = null): void
    {
        $this->addMediaConversion('thumb')
            ->greyscale();
        $this->addMediaConversion('optimized');
        $this->addMediaConversion('non-optimized')
            ->nonOptimized();
    }
    public function contract()
    {
        return $this->hasMany(Dogovor::class);
    }

    public function reports()
    {
        return $this->hasMany(Otchet::class);
    }

    public function passport()
    {
        return $this->hasMany(Passport::class, 'houses_id', 'id');
    }

    public function protocol()
    {
        return $this->hasMany(Protocol::class);
    }

}

Table Houses

id          bigint unsigned auto_increment
        primary key,
    home_number varchar(255)    null,
    street_id   bigint unsigned null,
    passport    text            null,
    report      text            null,
    contract     text            null,
    protocol    text            null,
    option        varchar(255)    null,
    aparts     varchar(255)    null,
    s_full      varchar(255)    null,
    s_life       varchar(255)    null,
    s_nolife     varchar(255)    null,
    status  varchar(255)    null,
    year        varchar(255)    null,
    created_at  timestamp       null,
    updated_at  timestamp       null,
    constraint house_street_id_foreign
        foreign key (street_id) references street (id)
)
Activity icon

Replied to Outputting Files To The View From The Database

ErrorException
Attempt to read property "document" on null
Activity icon

Replied to Outputting Files To The View From The Database

HomesController @ show

	 public function show($id)
    {
        $house = Houses::with(['street', 'passport'])->find($id);

        $house->street->name;
        $house->passport->document;
        return view('street.info', compact('house'));
    }

Passport Model

	protected $fillable = [
        'document',
    ];

    public function house()
    {
        return $this->belongsTo(Houses::class);
    }

House Model

 public function passport()
    {
        return $this->hasMany(Passport::class, 'houses_id', 'id');
    }