mardi 4 juin 2019

Make image download input correct in MetaTags model

I make on some questions about Laravel/PHP at StackOver and now i need your help too. I said at previous questions that i'm ruby/rails developer and for me PHP and Laravel is quiet danger :) I need to little bit support some project and i make my work at all, but now is question that i can't answer.

I need to make upload file + thumbnail preview for open_graph image tag. And the localpath url of uploaded image must be put to open_graph tag in app.blade - automaticaly

In this case - that i try to refactor my code - i have some problems 1) url of uploaded image in og_image tag have only name of downloaded file 2) sometimes object didn't save in database 3) in some cases this object - i save image for one module(news), and after i save it for another module(main_page) - it rewrites. I DB just dissapear object og_image for news and appears for main_page

This is strange. And i need your help. Thanks!

MetaTagsController

<?php

namespace App\Http\Controllers\Admin;

use Artisaninweb\SoapWrapper\Facades\SoapWrapper;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

/**
 * Class ContestController
 * @package App\Http\Controllers\Admin
 */
class MetaTagsController extends Controller
{
    /**
     * @param Request $request
     * @return \Illuminate\View\View
     */
    public function index(Request $request)
    {
        $meta_tags = \App\MetaTag::all();
        $arr_meta_tags = \Config::get('settings.arr_meta_tags');

        return view('admin.meta_tags.index', compact('meta_tags', 'arr_meta_tags'));
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse
     */
    public function store(Request $request)
    {
        $meta_tags = \App\MetaTag::all();
        foreach($meta_tags as $rw)
        {
            $rw->title = $request->get($rw->alias."_meta_title");
            $rw->description = $request->get($rw->alias."_meta_description");
            $rw->keywords = $request->get($rw->alias."_meta_keywords");
            $rw->og_title = $request->get($rw->alias."_og_title");
            $rw->og_description = $request->get($rw->alias."_og_description");
            $rw->og_type = $request->get($rw->alias."_og_type");
            $rw->og_image = $request->get($rw->alias."_og_image");
            $rw->save();
        }

        return back()->with('message', 'Настройки сохранены');
    }


}

MetaTag model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use App\Upload\Imageable;
use App\Upload\Uploadable;

/**
 * App\Setting
 *
 * @mixin \Eloquent
 */
class MetaTag extends Model
{

    use Uploadable, Imageable;

    /**
     * @var array
     */
    protected $table = "meta_tags";
    protected $fillable = ['title', 'description', 'keywords','og_type','og_title','og_description','og_image'];

       /**
     * @var array
     */
    protected $files = [
        'img',
        'og_image'
    ];

    /**
     * @var array
     */
    protected $file_casts = [
        'img' => 'image',
        'og_image' => 'image'
    ];

}

MetaTag index part

@foreach($meta_tags as $rw)
...
                        <div class="form-group">
                        {!! Form::label('og_image', 'Изображение', ['class' => 'control-label']) !!}
                        <div>
                            {!! Form::file('og_image') !!}
                            @if (isset($item) && $item && $item->img)
                                <div>
                                    <img src="" width="100%"/>
                                </div>
                            @endif
                        </div>
                    </div>
                        @endforeach



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire