-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/pack stickers #37
Open
Hasban-Fardani
wants to merge
2
commits into
main
Choose a base branch
from
feat/pack-stickers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,64 +2,84 @@ | |
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Pack; | ||
use App\Models\Sticker; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Storage; | ||
use Illuminate\Support\Facades\Validator; | ||
use Illuminate\Validation\Rules\File; | ||
|
||
use function PHPUnit\Framework\stringStartsWith; | ||
|
||
class StickerController extends Controller | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
*/ | ||
public function index() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Show the form for creating a new resource. | ||
*/ | ||
public function create() | ||
public function index(Pack $pack) | ||
{ | ||
// | ||
return $pack->stickers; | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
*/ | ||
public function store(Request $request) | ||
public function store(Request $request, Pack $pack) | ||
{ | ||
// | ||
$validator = Validator::make($request->all(), [ | ||
'name' => 'required|max:32', | ||
'image' => File::image()->max('10MB'), | ||
]); | ||
|
||
if ($validator->fails()) { | ||
return response()->json([ | ||
'message' => 'The given data was invalid.', | ||
'errors' => $validator->errors(), | ||
], 422); | ||
} | ||
|
||
// store image | ||
$path = $request->file('image')->store('stickers'); | ||
$request->merge(['image' => $path]); | ||
|
||
$sticker = $pack->stickers()->create($validator->validated()); | ||
|
||
return response()->json([ | ||
'message' => 'Sticker created successfully', | ||
'sticker' => $sticker | ||
]); | ||
} | ||
|
||
/** | ||
* Display the specified resource. | ||
*/ | ||
public function show(Sticker $sticker) | ||
public function show(Request $request, Pack $pack, Sticker $sticker) | ||
{ | ||
// | ||
} | ||
if ($request->has('download')) { | ||
if (stringStartsWith($sticker->image, 'http')) { | ||
$stickerExtension = explode('.', $sticker->image); | ||
$stickerExtension = $stickerExtension[1]; | ||
$filename = 'sticker' . '.' . $stickerExtension; | ||
$tempImage = tempnam(sys_get_temp_dir(), $filename); | ||
copy($sticker->image, $tempImage); | ||
|
||
/** | ||
* Show the form for editing the specified resource. | ||
*/ | ||
public function edit(Sticker $sticker) | ||
{ | ||
// | ||
} | ||
return response()->download($tempImage, $filename); | ||
} | ||
return response()->download(Storage::path($sticker->image)); | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
*/ | ||
public function update(Request $request, Sticker $sticker) | ||
{ | ||
// | ||
return $sticker; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's this? |
||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
*/ | ||
public function destroy(Sticker $sticker) | ||
public function destroy(Pack $pack, Sticker $sticker) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete the pack variable if it is not used |
||
{ | ||
// | ||
$sticker->delete(); | ||
return response()->json(['message' => 'Sticker deleted successfully.']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use json responses!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
laravel is atuomaticly convert model to json response so it will return like thi
{
"image": <image_path>,
"pack_id": <pack_id>
}
source: link
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the following format
{"status": bool, "data": dict}
{"status": bool, "message": string}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you have to follow the standards? because it will make it easier to process data