如何在其他页面上编辑时获取其他表上的图像


How to get image on other table while editing on other page

1)当用户编辑请愿书时,我试图获得一个图像,我有两个表请愿书和用户我想保存在用户表的profile_imgurl属性中的是用户图像

这是我在AdminPetitonController文件中的post_edit方法。

2)如何在这里使用热切加载,我的意思是只使用$SponceringUser而不是$ProfileUser。所以我不需要跑两次单独的查询

 public function post_edit($id = null)
{
    if ($id)
    {
        $Petition = Petition::find($id);
        if (!$Petition)
        {
            //oh noes! invalid petition specified!
            Alert::error("That petition no longer exists");
            return Redirect::action('AdminPetitionsController@index');
        }
    }
    else
    {
        $Petition = new Petition;
    }
    $PetitionCreationForm = new AdminPetitionCreationForm;
    $errors = array();
    if ($PetitionCreationForm->passes())
    {
        $Petition->call_to_action = Input::get('call_to_action');
        if (empty($Petition->id))
        {
            $Petition->slug = Str::slug($Petition->call_to_action);
        }
        $Petition->recipient = Input::get('recipient');

        if (Input::get('feature_type') == '1')
        {
            $Petition->featured_sort_order = Input::get('featured_sort_order') + 1;
            $Petition->flag_featured = 1;
        }
        else if(Input::get('feature_type') == '0')
        {
            $Petition->featured_sort_order=null;
            $Petition->flag_featured = 0;
        }
        //$selected_position = Input::get('dropdown_menu_list');
        $Petition->description_md = Input::get('description_md');
        $Petition->description = Petition::parseMD($Petition->description_md);
        $Petition->letter_md = Input::get('letter_md');
        $Petition->letter = Petition::parseMD($Petition->letter_md);
        $Petition->target_signatures = Input::get('target_signatures', 50000);
        $Petition->flag_published = Input::get('flag_published');
        $Petition->media_type = Input::get('media_type', null);
        if (Input::get('media_type') == 'img' && Input::hasFile('petition_image'))
        {
            $Petition->media_url = Petition::uploadFile(Input::file('petition_image'));
        }
        else if (Input::get('media_type') == 'youtube' && Input::get('media_url_youtube'))
        {
            $Petition->media_url = Input::get('media_url_youtube');
        }

        //  how to fix this part .... gurrrrrrrrrrrr=======================
        $ProfileUser= $Petition->User();
        if (Input::get('profile_type') == 'image' && Input::hasFile('profile_image'))
        {
            $ProfileUser->profile_img_url =  Petition::uploadFile(Input::file('profile_image'));
        }
        else if (Input::get('profile_type') == 'url' && Input::get('profile_url'))
        {
            $ProfileUser->profile_img_url = Input::get('profile_url');
        }
        //$Petition->sponsor_user_id = $SponsoringUser->id;
        $ProfileUser->save();
        //====================================================
        try {
            try {
                $SponsoringUser = User::where('email', Input::get('user.email'))->firstOrFail();
            }
            catch (Exception $e)
            {
                $PetitionSponsorForm = new AdminPetitionSponsorForm(Input::get('user'));
                if ($PetitionSponsorForm->passes())
                {
                    $SponsoringUser = new User;
                    $SponsoringUser->email = Input::get('user.email');
                    $SponsoringUser->first_name = Input::get('user.first_name');
                    $SponsoringUser->last_name = Input::get('user.last_name');
                    $SponsoringUser->populateLocation(Input::get('user.zip'));
                    $SponsoringUser->save();
                }
                else
                {
                    throw new Exception();
                }
            }
            $Petition->save();

如何具体修复那个部分(我强调了)我想我只是把那个部分搞砸了。它给了我一个错误,那就是save是一个未定义的方法。我不确定我是否需要制作另一个像$ProfileUser这样的变量。

有关更多详细信息,请参阅要点:https://gist.github.com/gupta2205/b33dcf762876e5df34d9

您的Gist不清楚,但您的请愿模型中是否设置了用户关系?

如果是,请尝试将有问题的行更改为:

$ProfileUser= $Petition->User;