ameenmathers
1 year ago

Trying to set up download for pdf in my db

Posted 1 year ago by ameenmathers

I have successfully uploaded my pdf to database but the function to download is not working and keeps showing me this error SQLSTATE[42S02]: Base table or view not found: 1146 Table 'pj.pdfs' doesn't exist (SQL: select * from pdfs where pdfs.cid = 2 and pdfs.cid is not null)

This my blade file

>      @foreach( $contracts as $contract)
                {{--{{$contract}}--}}

                <tr class="text-white">


                    <td>{{$contract->company->name}}</td>
                    <td>{{$contract->category->name}}</td>
                    <td>{{$contract->date_serviced}}</td>
                    <td>{{$contract->contract_date}}</td>
                    <td>{{$contract->location_desc}}</td>
                    <td>{{$contract->contract_expiration_date}}</td>
                    <td>{{$contract->past_due_penalty}}</td>
                    <td>{{$contract->billing_mail_address}}</td>
                    <td>{{$contract->billing_email_address}}</td>
                    <td>{{$contract->billing_contact_name}}</td>
                    <td>{{$contract->billing_contact_phone}}</td>
                    <td>{{$contract->account_number}}</td>
                    <td>{{$contract->signed}}</td>
                    <td><a class='btn btn-primary' href="{{url('update-contract/'. $contract->cid)}}">Update</a></td><br>
                    <td><a type='submit' name='action' class='btn btn-danger' href="{{url('delete-contract/' . $contract->cid) }}">X</a></td>


                    @foreach($contract->pdfs as $pdf)
                    <td><a href="{{$pdf->url}}" class="btn-floating btn-lg purple-gradient" download><i class="fa fa-bolt"></i></a></td>
                    @endforeach

                    @endforeach
                </tr>
        </table>

This is my pdf model code

>class pdf extends Model
{
    protected $table = 'pdfs';
    protected $primaryKey = 'pdid';
}

This is my contract model code

class contract extends Model
{
    protected  $table = 'contracts';
    protected $primaryKey ='cid';



    public function Category ()
    {
        return $this->belongsTo(category::class,'ctid');
//        return $this->hasManyThrough(Category::class,contract_category::class, 'cid','ctid', 'cid');
    }

    public function Company()
    {
        return $this->belongsTo(company::class,'cpid');
    }

    public function pdfs()
    {
        return $this->hasMany(pdf::class,'cid','cid');
    }

this is my schema

Schema::create('contracts', function (Blueprint $table) {
            $table->increments('cid');
            $table->integer('ctid');
            $table->integer('cpid');
            $table->string('date_serviced');
            $table->string('contract_date');
            $table->string('location_desc');
            $table->enum('rate',array('hourly','per_turn','per_flight','per_push'))->nullable();
            $table->string('contract_expiration_date');
            $table->string('past_due_penalty');
            $table->string('billing_mail_address');
            $table->string('billing_email_address');
            $table->string('billing_contact_name');
            $table->string('billing_contact_phone');
            $table->string('account_number');
            $table->string('signed');
            $table->timestamps();
        });

 Schema::create('pdfs', function (Blueprint $table) {
            $table->increments('pdid');
            $table->string('url',2000);
            $table->integer('cid');
            $table->timestamps();
        }

My controller code

 public function contractTable()
    {

        if(Input::has('q')){
           $term = Input::get('q');
            $contracts = company::where('name','like',"%$term%")->get();
        }else{
            $contracts = contract::all();

        }


//        return $contracts->company;


        return view('/contractTable',[
            'contracts' => $contracts
        ]);

    }

Please sign in or create an account to participate in this conversation.